Operating System - HP-UX
1753774 Members
6976 Online
108799 Solutions
New Discussion юеВ

file not found error, but the file exists.!

 
SOLVED
Go to solution
Marco Camacho_1
Frequent Advisor

file not found error, but the file exists.!

Hi all.
when i try to run script from a scheduler tool, i receive the message "file not found" I can ensure the path and name exists and are correct. What i observe is that some directorys have different owners (user & group) and the script also. I assume that when you not have the appropiate permissions, you can receive a messages as "permission denied" or "cannot execute", but i can not explain my self why i receive the "file not found" message if the file exists. Appreciate your help.
Mark-ito
7 REPLIES 7
Pete Randall
Outstanding Contributor

Re: file not found error, but the file exists.!

Is the file identified by full path name in the script? i.e. "/usr/local/bin/myfile" rather than just "myfile"?


Pete

Pete
Marco Camacho_1
Frequent Advisor

Re: file not found error, but the file exists.!

Yes Pete, we indicate the full path in the script command line in the scheduler tool (TWS). ie. /opt/script/bin/myshell.sh

if i do a copy paste from the line in the scheduler and add the ll command in a shell session, the file exists.

ll /opt/script/bin/myshell.sh
Mark-ito
OldSchool
Honored Contributor

Re: file not found error, but the file exists.!

Marco,

I believe Pete was referring to the file names / commands within the script being run, not the path to the script in the scheduler.

If your using cron, be aware that the environment it provides for a user is not the same as the users login environment. In particular, the PATH is very restricted.

Make sure your script sets PATH as you want it, all required environment variables are set. In addition, beware of relative path names. Unless you "cd" somewhere first, its almost a sure bet you aren't running in the location you think you are. Providing full paths to files will also work.

for example, if your script does:

cp abd /a/b/c/abd

it will fail if you're not in the correct directory it start with, so either change it to something like

cd /filedir
cp abd /a/b/c/abd

or

cp /filedir/abd /a/b/c/adb





James R. Ferguson
Acclaimed Contributor

Re: file not found error, but the file exists.!

hi:

Another consideration is that the verbiage of the message may be non-standard. If you use 'strerror()', for example, in a C program you map the errno of a failed function call to a catalog of standard strings. An errno=2 equates to "No such file or directory". An errno=13 is "Permission denied".

Too, be sure that if you are 'root' and have moved into a directory that you preface relative paths with a dot, as:

# cd /root
# ./myscript

Remember, 'root' does not nor should not have a dot ('.') in its PATH. To do so is a terrible security hole.

Regards!

...JRF...
Bill Hassell
Honored Contributor
Solution

Re: file not found error, but the file exists.!

The ability to find a file depends on the directory. If the directory does not give you permission to search the directory, giving the fullpath will not help -- the file is still not found. The owner of the directory can find and open the file but permissions can restrict other users.

Try this (not as root):

mkdir /tmp/blh
touch /tmp/blh/findme
ll /tmp/blh/findme

(the above ll works OK)

chmod 700 /tmp/blh
chown root /tmp/blh
ll /tmp/blh/findme

Now the ll fails with:

/tmp/blh/findme not found

Login as root and you can once again see the file. The 700 permissions restrict your ability to search the directory. All standard UNIX directory permission stuff.


Bill Hassell, sysadmin
Marco Camacho_1
Frequent Advisor

Re: file not found error, but the file exists.!

Thanks a lot for your kindly help, all your comments will allow me to fix the problem.
Marco C.
Mark-ito
OldSchool
Honored Contributor

Re: file not found error, but the file exists.!

that's nice, but *what fixed it*?