Not found [No such file or directory], although the file present in this directory in RH Linux 6.2

When Im runs a script from Linux (RH Linux 6.2), it does not detect an error [There is no such file or directory], even if the file is present in this directory (permissions are checked, and they are fine).

Example:

md1silinux04:/data/upgrade> /data/upgrade/upgrade_db.ksh -ksh: /data/upgrade/upgrade_db.ksh: not found [No such file or directory] md1silinux04:/data/RAIL/rpo402/db/upgrade> ls /data/upgrade/upgrade_db.ksh /data/upgrade/upgrade_db.ksh 

Can anyone help with this?

+7
linux shell
source share
4 answers

Perhaps you have ctrl-M (carriage return) at the end of each line of your file.

View: cat -v / data / upgrade / upgrade_db.ksh

To fix: perl -p -i -e "s / \ r // g" / data / upgrade / upgrade _db.ksh

+5
source share

Enter this:

 ls -ls /data/RAIL/rpo402/db/upgrade 

List the results for the file and view its permissions.

Make sure the file is not empty. Make sure the file has permissions to run as a shell.

 chmod +x upgrade_db.ksh 

Look at the first line of the file, make sure that it has the correct header for the shell script. Perhaps Korn Shell requires a shell declaration in the header.

Check dmesg to see if there are any error messages, possibly the file system and check inodes.

0
source share

Try the following:

  • ksh / data / upgrade / upgrade_db.ksh

or while you have the current data directory / upgrade /

  • ../upgrade_db.ksh
0
source share

Despite the unlikely problem of OP, a fairly similar error message - it brought me here - may appear if your shebang is of a character. In my case, the script is still running, but the error is very annoying - especially since I help someone with their "official" procedure, and errors in such cases are undesirable.

Output Example:

 CS-015: # /bin/ksh check.sh check.sh[1]: ๏ปฟ#!/bin/ksh: cannot execute - No such file or directory check.sh 

As a result, the cat shows how:

 $ cat check.sh #!/bin/ksh THIS_SCRIPT="$(basename $0)" echo "$THIS_SCRIPT" exit 0 # Nothing else matters; I had narrowed it to here... 

In this case, I inherited the file, and hexdump shows:

 $ hexdump -C check.sh 00000000 ef bb bf 23 21 20 2f 62 69 6e 2f 6b 73 68 0a 0a |...#! /bin/ksh..| 00000010 54 48 49 53 5f 53 43 52 49 50 54 3d 22 24 28 62 |THIS_SCRIPT="$(b| ... 

As Stefan Shazelas suggests at https://unix.stackexchange.com/a/381263/17300 , you can remove this with sed:

 $ sed -i '1s/^\xEF\xBB\xBF//' check.sh 
0
source share

All Articles