LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 08-06-2013, 07:57 PM   #1
jodib
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Rep: Reputation: Disabled
Question 'Permission denied' executing .sh from mounted vfat USB


Upgraded my Linux distro. and encountering (?permission?) problems running scripts on mounted USB drives. For example:

Code:
root@me:~# mkdir /mmm
root@me:~# mount /dev/sdc1 /mmm
root@me:~# echo "echo hi" > /mmm/try.sh
root@me:~# chmod 777 /mmm
root@me:~# chmod 777 /mmm/try.sh
root@me:~# /mmm/try.sh

root@me:~# /mmm/try.sh
bash: /mmm/try.sh: Permission denied

root@me:~# /bin/sh /mmm/try.sh 
hi

root@me:~# cp /mmm/try.sh /root/try.sh
root@me:~# chmod 777 /root/try.sh
root@me:~# /root/try.sh
In other words, no matter what I do with chmod and/or chgrp doesn't help. But if I copy the same script from the USB to a local filesystem then it works.

Puzzled, not sure where to look. SELinux doesn't seem to be on.

Mount shows:
/dev/sdc1 on /mmm type vfat (rw,relatime,fmask=0022,dmask=0077,codepage=cp437,iocharset=utf8,shortname=mixed,showexec,utf8,flush ,errors=remount-ro)
 
Old 08-06-2013, 08:14 PM   #2
MS3FGX
LQ Guru
 
Registered: Jan 2004
Location: NJ, USA
Distribution: Slackware, Debian
Posts: 5,852

Rep: Reputation: 361Reputation: 361Reputation: 361Reputation: 361
FAT doesn't support the extended Unix permissions, so you can't set it as executable, and thus it can't be executed.

As a workaround you should be able to mount the whole partition with the "exec" option, but that will make all files executable so be careful.
 
Old 08-06-2013, 08:21 PM   #3
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
well, seeing as it is a shell script, just point at it..

Code:
bash /mmm/try.sh
 
Old 08-06-2013, 08:22 PM   #4
Sydney
Member
 
Registered: Mar 2012
Distribution: Scientific Linux
Posts: 147

Rep: Reputation: 36
It also looks like you are able to launch the script if you specify the interpreter. Is the #! line of your script tainted with a DOS EOL or the path maybe wrong on it? If it is a DOS EOL you could run
Code:
sed -i -e 's/.$//g' try.sh
to remove it.
 
Old 08-06-2013, 08:26 PM   #5
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
ahh, good point Sydney

try this

Code:
cat > /mmm/try.sh << "EOF"
#!/bin/bash
echo "Hello World!"
EOF
chod 700 ./mmm/try.sh # never 777, unless you really, *really* need it
./mmm/try.sh
 
Old 08-06-2013, 08:41 PM   #6
jodib
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
@MS3FGX: I've tried specifying 'exec' option when I mount, no difference

Code:
mount -t vfat -o rw,auto,user,fmask=0022,dmask=0000,exec /dev/sdc1 /mmm
@Firerat: yes prefixing it with /bin/bash (or /bin/sh) works - but I'm not sure why I didn't need this before

@Sydney and Firerat: adding the first line #!/bin/bash doesn't make a difference - still get "Permission denied"


One more item I noticed is that the chmod 777 doesn't affect the file permissions. I suspect MS3FGX's point about FAT is the reason - but why did all this work before? What's changed?
 
Old 08-06-2013, 08:46 PM   #7
jodib
LQ Newbie
 
Registered: Aug 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Aha Found the problem!

The USB drive was mounted twice - the 1st by the OS (some automatic) as /media/Lexar and the 2nd by me. That 1st/auto had "showexec" flag which I suspect was the problem or overriding whatever I specified during my mount. Once I umounted /media/Lexar, then my mount flags would work.

Thanks all!
 
Old 08-06-2013, 08:51 PM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Quote:
Originally Posted by jodib View Post
@Firerat: yes prefixing it with /bin/bash (or /bin/sh) works - but I'm not sure why I didn't need this before
Yeah, my fault I totally missed that in your OP
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Permission denied executing cgi-script Geminias Linux - Networking 4 07-31-2006 10:02 PM
User executing script: bad interpreter: Permission denied stefaandk Linux - Newbie 7 06-27-2005 09:53 AM
permission denied executing /proc/version syandoa Linux - Newbie 2 03-16-2004 01:02 PM
permission denied when executing my own script Red Squirrel Linux - Newbie 3 03-07-2004 08:21 PM
Permission denied to drive when mounted at boot wr3ck3d Linux - General 2 12-30-2003 03:38 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration