OS=CentOS-5.2 media=Kingston 512Mb usb key Problem: As 'root', when running a script resident on the external drive mounted at /media/disk I receive the following error: /bin/sh: bad interpreter: Permission denied The meduia is a 512Mb USB key formatted as ext2/3 # ll -rwx------ 1 root root 28 Jul 2 17:30 hello.sh # cat hello.sh #!/bin/sh echo Hello World! # which sh /bin/sh I believe that this can be resolved by an entry in /etc/fstab but I cannot determine what entry to make. # cat /etc/fstab /dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 devpts /dev/pts devpts gid=5,mode=620 0 0 tmpfs /dev/shm tmpfs defaults 0 0 /dev/VolGroup00/LogVol03 /home ext3 defaults 1 2 proc /proc proc defaults 0 0 sysfs /sys sysfs defaults 0 0 /dev/VolGroup00/LogVol02 /tmp ext3 defaults 1 2 /dev/VolGroup00/LogVol04 /var/log ext3 defaults 1 2 /dev/VolGroup00/LogVol05 /var/www ext3 defaults 1 2 /dev/VolGroup00/LogVol01 swap swap defaults 0 0>From the logs I gather that the device is sda1Jul 2 16:42:45 inet02 kernel: SCSI device sda: 1001472 512-byte hdwr sectors (513 MB) Jul 2 16:42:45 inet02 kernel: sda: Write Protect is off Jul 2 16:42:45 inet02 kernel: sda: assuming drive cache: write through Jul 2 16:42:45 inet02 kernel: sda: sda1 Jul 2 16:42:45 inet02 kernel: sd 0:0:0:0: Attached scsi removable disk sda Jul 2 16:42:45 inet02 kernel: EXT2-fs warning: mounting unchecked fs, running e2fsck is recommended Jul 2 16:42:46 inet02 hald: mounted /dev/sda1 on behalf of uid 500 I deduce from the various bits of information that I have gleaned thatthe proper entry in fstab should be something like: /dev/sda1 /disk auto defaults,user,exec 0 0 However, this is an automounted, removable media. How do I do enable execute for this key and retain the auto mount capability? What impact will this have on other usb keys? -- *** E-Mail is NOT a SECURE channel *** James B. Byrne mailto:ByrneJB at Harte-Lyne.ca Harte & Lyne Limited http://www.harte-lyne.ca 9 Brockley Drive vox: +1 905 561 1241 Hamilton, Ontario fax: +1 905 561 0757 Canada L8E 3C3
James B. Byrne wrote:> Problem: > As 'root', when running a script resident on the external drive mounted at > /media/disk I receive the following error: > > /bin/sh: bad interpreter: Permission denied > >Usually, I've found this is because the file is stored with DOS style line endings. Maybe you could try: dos2unix -n hello.sh hello2.sh chmod +x hello2.sh ./hello2.sh Does that fix it? Greg
> As 'root', when running a script resident on the external drive mounted at > /media/disk I receive the following error: > > /bin/sh: bad interpreter: Permission deniedAre you sure the script isn't in DOS format, with CRLF line endings? If so then the interpreter it's trying to run is actually /bin/sh^M (with a control-M at the end). Which is wrong :-) Try running dos2unix on it and trying it again. -- rgds Stephen
Nicolas Thierry-Mieg
2008-Jul-03 15:29 UTC
[CentOS] Running shell scripts from external media
James B. Byrne wrote:> OS=CentOS-5.2 > media=Kingston 512Mb usb key > > Problem: > As 'root', when running a script resident on the external drive mounted at > /media/disk I receive the following error: > > /bin/sh: bad interpreter: Permission denied ><snip>> I deduce from the various bits of information that I have gleaned thatthe > proper entry in fstab should be something like: > > /dev/sda1 /disk auto defaults,user,exec 0 0 > > However, this is an automounted, removable media. How do I do enable > execute for this key and retain the auto mount capability? What impact > will this have on other usb keys?I think you have the right diagnostic, the key is mounted with the noexec flag. You can confirm this by typing "mount" when the usb key is mounted. But I don't know the answers to your questions... However if it fits your usefase you could invoke the shell yourself: /bin/sh hello.sh