When I’m executing a script from Linux (RH Linux 6.2), it is giving not found [No such file or directory] error, even though the file is present in that directory (checked the permissions 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
Could anybody please help on this ?
We can use Linux commands such as objdump, ldd, and readelf to check all the libraries that the binary needs and to check if our system has the program interpreter to run the binary.
First, make sure you execute the program with the correct path. If you make a typo on the directory or file name, you will get this error or give the wrong path. If you are executing the file with a relative path ( ../../file ), try executing with the absolute path ( /path/to/file ) instead.
The error "FileNotFoundError: [Errno 2] No such file or directory" is telling you that there is no file of that name in the working directory. So, try using the exact, or absolute path. In the above code, all of the information needed to locate the file is contained in the path string - absolute path.
In some cases, this error could be shown when the path of the specified file or folders exceeds 258 characters in length. The way to solve this is to reduce the length of the full path to the items specified, either by moving or renaming the file(s) and/or containing folders.
Perhaps you have ctrl-M (carriage returns) at the end of each line in your file.
To view:
cat -v /data/upgrade/upgrade_db.ksh
To fix:
perl -p -i -e "s/\r//g" /data/upgrade/upgrade_db.ksh
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With