WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Using sudo on an SMB share: command not found  (Read 2425 times)

Offline vbs

  • Newbie
  • *
  • Posts: 21
Using sudo on an SMB share: command not found
« on: April 17, 2015, 03:57:26 PM »
Guys, I have a strange problem on my Raspi2. I can start executables from a mounted SMB share without problems as a regular user. But every time I try to start an executable from that SMB share using "sudo" I get the message "command not found". I cant find the reason for this behavior. Maybe I miss something obvious but I think its strange. I tested the same thing on an x86-TC and on Ubuntu and it works fine there.

I am using this image "piCore-6.1beta1_v7-X.zip" and I have mounted an SMB-share using command:
Code: [Select]
mount -t cifs //ben/MASS2 /mnt/MASS2 -o user=me,password=secret,uid=1001,gid=50
Now there is the executable shell script "/mnt/MASS2/test.sh". As a normal user I can execute it and it gives the expected output:
Code: [Select]
tc@rasp_sz:~$ /mnt/MASS2/test.sh
works

Now the strange part: When I execute it using "sudo", then it claims it cannot find the executable:
Code: [Select]
tc@rasp_sz:~$ sudo /mnt/MASS2/test.sh
sudo: /mnt/MASS2/test.sh: command not found

Also when using sudo but changing to user "tc":
Code: [Select]
tc@rasp_sz:~$ sudo -u tc /mnt/MASS2/test.sh
sudo: /mnt/MASS2/test.sh: command not found

After copying test.sh from the SMB share to the local filesystem I can execute it without problems:
Code: [Select]
tc@rasp_sz:~$ sudo /mnt/MASS2/test.sh
sudo: /mnt/MASS2/test.sh: command not found
tc@rasp_sz:~$ cp /mnt/MASS2/test.sh /tmp/
tc@rasp_sz:~$ sudo /tmp/test.sh
works

This is the output of ls for MASS2:
Code: [Select]
tc@rasp_sz:~$ ls -la /mnt/MASS2/
total 1966102
drwxr-xr-x    2 tc       staff            0 Dec 19  2012 $RECYCLE.BIN/
drwxr-xr-x    2 tc       staff         8192 Apr 17 19:11 ./
drwxr-xr-x    5 root     root           100 Apr 17 19:46 ../
drwxr-xr-x    2 tc       staff            0 Apr  5 22:02 Audio/
drwxr-xr-x    2 tc       staff            0 Jan 24 20:35 Backup/
drwxr-xr-x    2 tc       staff            0 Dec 26 14:21 System Volume Information/
-rwxr-xr-x    1 tc       staff         5632 Dec 21  2013 Thumbs.db
drwxr-xr-x    2 tc       staff            0 Mar 12 16:50 VMs/
drwxr-xr-x    2 tc       staff            0 Nov 23 12:00 Video/
drwxr-xr-x    2 tc       staff            0 Apr 15 08:16 fhem-tc/
-rwxr-xr-x    1 tc       staff         2343 Jan 21 00:48 mydata.tgz
drwxr-xr-x    2 tc       staff            0 Apr  3 00:03 nginx/
-rwxr-xr-x    1 tc       staff           27 Jan  1  1970 onboot.lst
-rwxr-xr-x    1 tc       staff    2013265920 Apr 16 23:04 pagefile.sys
drwxr-xr-x    2 tc       staff            0 Apr 17 18:24 rasp/
drwxr-xr-x    2 tc       staff            0 Apr 17 19:11 rasp_sz/
-rwxr-xr-x    1 tc       staff          188 Apr  5 14:26 regex.pl
drwxr-xr-x    2 tc       staff            0 Nov  8 12:42 rips_ul/
-rwxr-xr-x    1 tc       staff           13 Apr 17 21:32 test.sh
drwxr-xr-x    2 tc       staff            0 Mar 28 00:10 userWidgets/

I have these extensions loaded:
Code: [Select]
tc@rasp_sz:~$ cat /etc/sysconfig/tcedir/onboot.lst
openssh.tcz
zip.tcz
wireless-3.18.10_v7-piCore+.tcz
libiw.tcz
iw.tcz
wireless_tools.tcz
wpa_supplicant.tcz
firmware-ralinkwifi.tcz
filesystems-3.18.10_v7-piCore+.tcz
libusb-compat.tcz
mc.tcz

Any idea what I can do? Thanks! Do you need any additional information?

Offline bmarkus

  • Administrator
  • Hero Member
  • *****
  • Posts: 7183
    • My Community Forum
Re: Using sudo on an SMB share: command not found
« Reply #1 on: April 18, 2015, 01:36:14 AM »
Check test.sh Usually 'Not found' means that program assigned to script in first line, #!... is not available.
Béla
Ham Radio callsign: HA5DI

"Amateur Radio: The First Technology-Based Social Network."

Offline vbs

  • Newbie
  • *
  • Posts: 21
Re: Using sudo on an SMB share: command not found
« Reply #2 on: April 18, 2015, 03:39:41 AM »
Hm, I added a shebang line so it looks like this but the problem still persists:
Code: [Select]
#!/bin/sh
echo "works"

Also the problem occurs with a natively compiled C-program:
Code: [Select]
tc@rasp_sz:/mnt$ sudo /mnt/MASS2/fhem-tc/airsensor/airsensor_arm -d
sudo: /mnt/MASS2/fhem-tc/airsensor/airsensor_arm: command not found

Works without sudo:
Code: [Select]
tc@rasp_sz:/mnt$ /mnt/MASS2/fhem-tc/airsensor/airsensor_arm -d
2015-04-18 09:39:02, DEBUG: Active
2015-04-18 09:39:02, DEBUG: Init USB

So strange  :-[

Offline Greg Erskine

  • Sr. Member
  • ****
  • Posts: 404
Re: Using sudo on an SMB share: command not found
« Reply #3 on: April 18, 2015, 03:49:33 AM »
Could it be root doesn't have read access to the MASS2 directory?

Offline vbs

  • Newbie
  • *
  • Posts: 21
Re: Using sudo on an SMB share: command not found
« Reply #4 on: April 18, 2015, 04:21:07 AM »
As far as I can see it has:
Code: [Select]
tc@rasp_sz:/mnt$ ls -al
total 12
drwxr-xr-x    6 root     root           120 Apr 18 09:57 ./
drwxr-xr-x   17 root     root           380 Jan  1  1970 ../
drwxr-xr-x    2 tc       staff         8192 Apr 18 09:57 MASS2/
drwxr-xr-x    2 root     root            40 Jan  1  1970 mmcblk0p1/
drwxr-xr-x    4 root     root          4096 Jan  1  1970 mmcblk0p4/
drwxr-xr-x    2 root     root            40 Apr 18 09:57 test/

Also root can ls fine on MASS2:
Code: [Select]
tc@rasp_sz:/mnt$ sudo ls -la /mnt/MASS2/
total 1966922
drwxr-xr-x    2 tc       staff            0 Dec 19  2012 $RECYCLE.BIN
drwxr-xr-x    2 tc       staff         8192 Apr 18 09:57 .
drwxr-xr-x    6 root     root           120 Apr 18 09:57 ..
drwxr-xr-x    2 tc       staff            0 Apr  5 22:02 Audio
drwxr-xr-x    2 tc       staff            0 Jan 24 20:35 Backup
-rwxr-xr-x    1 tc       staff       835792 Apr 18 09:57 DPO_RT5572_LinuxSTA_2.6.1.3_20121022.tar.bz2
drwxr-xr-x    2 tc       staff            0 Dec 26 14:21 System Volume Information
-rwxr-xr-x    1 tc       staff         5632 Dec 21  2013 Thumbs.db
drwxr-xr-x    2 tc       staff            0 Mar 12 16:50 VMs
drwxr-xr-x    2 tc       staff            0 Nov 23 12:00 Video
drwxr-xr-x    2 tc       staff            0 Apr 17 22:53 fhem-tc
-rwxr-xr-x    1 tc       staff         2343 Jan 21 00:48 mydata.tgz
drwxr-xr-x    2 tc       staff            0 Apr  3 00:03 nginx
-rwxr-xr-x    1 tc       staff           27 Jan  1  1970 onboot.lst
-rwxr-xr-x    1 tc       staff    2013265920 Apr 16 23:04 pagefile.sys
drwxr-xr-x    2 tc       staff            0 Apr 17 18:24 rasp
drwxr-xr-x    2 tc       staff            0 Apr 17 19:11 rasp_sz
-rwxr-xr-x    1 tc       staff          188 Apr  5 14:26 regex.pl
drwxr-xr-x    2 tc       staff            0 Nov  8 12:42 rips_ul
-rwxr-xr-x    1 tc       staff           23 Apr 18 09:35 test.sh
drwxr-xr-x    2 tc       staff            0 Mar 28 00:10 userWidgets