VMware Cloud Community
crrice
Contributor
Contributor

linux shell script, error, "bad interpreter no such file or directory"

Someone Help Please,

I am trying to get a Linux shell script to run on an ESX host and keep getting the error "bad interpreter no such file or directory. Now I will give the details to this issue which is driving me crazy...

I created a small script using the interpreter of #!/bin/sh, this script does the following:

#!/bin/sh

mount -t smbfs -o username=xxx/xxx //xxx/lan /mnt/isos

cp -r /mnt/isos/vmimages/patrol.d /etc/

chown root /etc/patrol.d

cp /mnt/isos/vmimages/postinstall.sh /tmp/

chmod ugo=rwx /tmp/postinstall.sh

cp /mnt/isos/vmimages/license /opt/bmc/Patrol3/lib/

echo "cd /opt/bmc/Patrol3; ./PatrolAgent -p 2112 -id `hostname -s` -rtserver tcp:x.x.x.x:2059" >> /tmp/postinstall.sh

umount /mnt/isos

cd /tmp; ./postinstall.sh

Now, the script I created as you can see mounts a drive, copies over a couple of files, changes some ownership and perms, edits one of the files it has copied over which is the script in question, then as the last step it is supposed to execute the script called "postinstall.sh" That is where I get the error but I can't figure out why because the first line of the "postinstall.sh" script is the same as my original script, it starts with #!/bin/sh

Now I have checked the ownership and perms of the "postinstall.sh" script and they are as follows:

-rwxrwxrwx 1 root root 1032 Jun 11 15:40 postinstall.sh

So, this tells me that the script is there, that the owner is root, and that it is read, write, and execute for everyone. As for the "bad interpreter" part of the message, the first lines are the same in both scripts so that should not be an issue. Just for safe measure here is the output showing that the shells are there and are installed in the /bin directory:

bin]$ ls

arch dmesg ipcalc pgawk sync

ash dnsdomainname kbd_mode ping tar

ash.static doexec kill ps touch

awk domainname link pwd tracepath

basename dumpkeys ln raw true

bash[/b] echo loadkeys rm umount

bash2[/b] egrep login rmdir uname

bsh env login.emergency rpm unicode_start

cat ex ls rvi unicode_stop

chgrp false mkdir rview unlink

chmod fgrep mknod sed usleep

chown gawk mktemp setfont vi

cp grep more setserial view

cpio gtar mount sh[/b] ypdomainname

cut gunzip mv sleep zcat

date gzip netstat sort

dd hostname nice stty

df igawk nisdomainname su

bin]$

If I try to run the "postinstall.sh" script manually I get the same error. I have also tried changing the first line to #!/bin/bash but that doesn't help either. So can anyone please tell me what in the world is going on and why that script won't run?????

Any help would be greatly appreciated. I am running out of time to get this issue resolved !!!!!!!!

0 Kudos
5 Replies
MR-T
Immortal
Immortal

When you execute the script are you running .//sh

./postinstall.sh[/b]

0 Kudos
crrice
Contributor
Contributor

Yes, that is exactly what I have typed in the script and what I type when I try to run it manually.

Thanks,

Chris

0 Kudos
ABu
Enthusiast
Enthusiast

it starts with #!/bin/sh

Are you sure? Sometimes there are some "special characters" like TAB or "\0x0d\0x0a" or so at the end of line.

Can you give us the output from

head -2 /tmp/postinstall.sh | od -xc

ABu.

0 Kudos
MR-T
Immortal
Immortal

ok, so when you're running this script who are you logged in as?

If you used su, did you include the minus -

so

su -

If not, you'll get odd errors like this as the environment variables and paths won't work.

0 Kudos
xinetd
Contributor
Contributor

Hi,

Though it is late, but i think never is better than too late. This issue is due to format of the file. Probably you have copied it from Windows boxes over to unix box. If so try doing this.

Open the file in vi , then give the command in vi :set fileformat=unix , Save and exit the editor. that should solve the problem.

0 Kudos