views:

558

answers:

4

Can anyone enlighten me why the following won't work?

$ groups
  staff btgroup
$ ls -l
  total 64
  -rw-rw----    1 sld248   btgroup       26840 Apr 02 13:39 padaddwip.jks
  -rwxrwx---    1 sld248   btgroup        1324 Apr 02 13:39 padaddwip.ksh
$ ./padaddwip.ksh
  ksh: ./padaddwip.ksh:  not found.
$ echo $?
  127

This is nearly identical to another script which works just fine. I can't see any differences between the two in terms of permissions or ownership.

thanks in advance!

+1  A: 

just a guess, check your shebang in padaddwip.ksh. it should be something like #!/bin/ksh. If not, use which ksh to see where your ksh is installed. Alternatively, you can execute your script by calling the interpreter(ksh) eg

$ /bin/ksh padaddwip.ksh

another way you can do is changing your shebang to #!/usr/bin/env ksh

Also, make sure the user executing the script has its primary group as btgroup

ghostdog74
First line of script shows: #!/bin/kshAnd 'which ksh' shows: /usr/bin/ksh
Chris Knight
then why don't you try changing your shebang to that of `/usr/bin/ksh` and see.
ghostdog74
Thanks ghostdog74, I think your recommendation will work. Interestingly, the output of /bin/ksh padaddwip.ksh is: $ /bin/ksh padaddwip.ksh padaddwip.ksh[13]: ^M: not found. padaddwip.ksh[14]: ^M: not found. padaddwip.ksh[17]: ^M: not found. Logging all output to padaddwip.log ....Is it these ^M characters which are causing the issue?
Chris Knight
ah, then you should remove those `^M` using tools like `dos2unix`
ghostdog74
+1  A: 

There may be 2 problems:

  • Shebang line is wrong (as ghostdog alluded to)

  • The script was saved from Windows and has DOS line endings.

Foe the latter, do

head padaddwip.ksh | cat -vet | head -1

The command should produce the shebang line NOT ending with "^M". If it does end with "^M" that's a DOS-encoded file, and the fix is:

cp padaddwip.ksh padaddwip.ksh.bak
dos2unix padaddwip.ksh.bak > padaddwip.ksh
./padaddwip.ksh

On systems without dos2unix, you can use

cat padaddwip.ksh.bak | tr -d "\r" > padaddwip.ksh
DVK
OK, thanks DVK, I think you're right. My other script which works does not have the ^M at the end of each line, but the script which doesn't work does have the ^M at the end of each line. Unfortunately, dos2unix isn't installed on my AIX server (and I don't have root priviledges). I shall pester the powers that be. Is there a way to FTP a file to an AIX server which would strip/convert correctly?
Chris Knight
@Chris - Yes. Set "ascii" mode in FTP
DVK
@Chris - also, in the abscence of dos2unix, just run `cat padaddwip.ksh.bak | tr -d "\r" > padaddwip.ksh`
DVK
Fantastic, thanks
Chris Knight
+1  A: 

Another way to rid your scripts of the annoying ^M characters would be to open the file in vi and type :%s/^M//g (sed within vi) where the ^M here is created by typing Ctrl-V then Ctrl-M. I personally like this method because you don't need to create a backup file and you instantly see the results -just an OCD habit of mine-

Also, I have had some weird problems with using tr and control characters such as \r it may have been a shell or site-specific issue, but in such cases I needed to use either the above method or sed from the command line...very to similar what DVK shows above; like sed -e 's/^M//g' padaddwip.ksh.bak > padaddwip.ksh where you create the ^M by doing Ctrl-V then Ctrl-M (when in vi editor mode).

Sean
I'll admit to not knowing VI at all, but thanks for the useful response.
Chris Knight
A: 

the shebang is bad.

test the scenario with the shell interpreter on the cmdline.

ksh padaddwip.ksh
masta

related questions