-ksh: revenue_ext.ksh: not found [No such file or directory]

I am getting the same not found [No such file or directory] error when trying to execute a ksh script. Read tips about the PATH and running the script with a ./ in the posts here and here and tried but no luck. The script does exist under the directory from where I am trying to execute and has full permissions but gives the same error when run directly or with a ./. The first line within the script also has #!/usr/bin/ksh

The error message is like below:

-ksh: revenue_ext.ksh: not found [No such file or directory]

However, other ksh scripts under the same directory run fine so am absolutely clueless about what could be wrong here. Any help would be greatly appreciated

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

I believe there may be some carriage returns causing this error here. I was able to reproduce the error successfully.

Testing

cat ksh_experiment.ksh

#!/usr/bin/ksh
echo "Hello"

Now after providing the permissions when I ran the file, it produced the output successfully. Now as discussed over here, I inserted some carriage returns in my file. Now when I ran the script, I was getting the output as,

ksh: ./ksh_experiment.ksh: not found [No such file or directory]

Now, cat -v ksh_experiment.ksh too produced the same output. Also, if I typed vim ksh_experiment.ksh , a new file was getting opened.

As discussed in the answer of the link that I provided, I removed the carriage returns using the command,

 perl -p -i -e "s/\r//g" ksh_experiment.ksh

After fixing when I ran, I got the output as expected.

Solution 2

In my case, I had this same error message come up if the file is either .ksh or .sh like this:

-ksh: ./somefile.sh: not found [No such file or directory]

Turns out its the access issue.

Even though you make this file executable, on the server you might need admin rights to run. I could run command line, but executing the script would return not found, try run the script in sudo, then you will know if you are allowed to run the script as root or not.

Solution 3

This happens due to ^M characters.

Try using dos2unix <File_name> and we should be okay to get expected results.

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply