Cron errors with : No such file or directory

Hello,

    One of our customers has a script that needs to run nightly via cron. If you run the file manually it throws a BAD open((null)) error but they assure me that it works for them. When I try to put the location in a cron under that same user it throws a ": No such file or directory" error. I even tried to embed another script to run it as bin/bash and that has not helped. Is there any way to debug this problem?

Thanks,
Nick
mw-hostingAsked:
Who is Participating?
 
mw-hostingAuthor Commented:
Issue has been resolved by adding 2> /dev/null & to the end of the line.
0
 
martin_2110Commented:
Try running dos2unix on it.
dos2unix file_name
0
 
martin_2110Commented:
if it is bash you can run it with bash -x to debug. or perl -d if its perl.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
mister2walkerCommented:
Need some more information:
1. Are you using absolute paths? (eg. /home/user/john/somefile.dat  as opposed to $SOMEPATHVARIABLE/somefile.dat)
2. Is the script attempting to touch a file outside of the users' home directory path?  If so, are you certain that the mask is set correctly on the file that the script is trying to touch(eg. chmod 775 filename)?
3. Are you setting environment variables in the script for path or any other substitution related to the file that the script is trying to touch?

0
 
mw-hostingAuthor Commented:
I'm using the full path /home/john/scriptfile. This script processes files in another user's home directory. That directory is set to full access. If you run the script manually it populates data in that other user's directory.

0
 
martin_2110Commented:
can you send the output of bash -x /home/john/scriptfile
0
 
mw-hostingAuthor Commented:
I get an error: Cannot execute binary file.

0
 
mister2walkerCommented:
Need some more information:
1. Are you using absolute paths? (eg. /home/user/john/somefile.dat  as opposed to $SOMEPATHVARIABLE/somefile.dat)
2. Is the script attempting to touch a file outside of the users' home directory path?  If so, are you certain that the mask is set correctly on the file that the script is trying to touch(eg. chmod 775 filename)?
3. Are you setting environment variables in the script for path or any other substitution related to the file that the script is trying to touch?

0
 
mister2walkerCommented:
ok.  More questions:
1. Does /home/john/scriptfile use any variables defined defined in ~/.profile or /etc/profile to do its' job?  For example, do you use the other user's absolute path inside the scriptfile to find the other file?
2. Do you create or use any temp files when you're doing operations on the file to move data or change things?
3. When you run it manually, are you running it as the user 'john' or as sudo or an admin user?
0
 
mister2walkerCommented:
The other approach similar to Martin's request is to run bash in debug at the cron level so you get the direct effect of the cron environment setup when executed.

So modify your call in cron to execute the following

bash -x /home/john/scriptfile 1>/home/john/scriptfile.log 2>&1

You will get the details, know which line in the script throws the error, and both stdout and stderr will output to the scriptfile.log file in the user's home directory.
0
 
mw-hostingAuthor Commented:
It's a binary file so I don't think any of this will work.
0
 
omarfaridCommented:
check if there are env variables that should be set
0
 
mw-hostingAuthor Commented:
The env variables wouldn't matter because I created a shell script running as bin/bash so the same env variables would be loaded for the script under the cron.
0
 
omarfaridCommented:
env variables are not loaded when you run crontab jobs, you should set them in the script
0
 
fosiul01Commented:
Hi,
Can you run  this job run under root user ??

As Omarfarid said, it most likely that the cron is not getting bash path for this user ( if the file extension is script.sh)



try under root user, see if this works,
0
 
mister2walkerCommented:
Exactly.  When you run scripts under cron, you have to be careful to deliberately source the environment (eg. ". ~john/.profile" to get any path or other variables that might be in your login profile to help this script, if it indeed uses any of the variables.

The fact that the file being manipulated is binary is irrelevant for the purposes of debugging the script.  The key is to get the debug output of the script into a log file so you can see where the failure is.  Try the modified call that I suggested in the command section of your cron entry
"bash -x /home/john/scriptfile 1>/home/john/scriptfile.log 2>&1"
0
 
mw-hostingAuthor Commented:
Ok here is how I have the cron setup:

14 10 * * 1-5 "bash -x /home/tracker/prod/MMExe 1> /home/tracker/prod/MMExe.log 2>&1"

This is what is returned:
: No such file or directoryker/prod/MMExe 1> /home/tracker/prod/MMExe.log 2>&1
0
 
omarfaridCommented:
I think you don't need " round the command. Also, are you able to run the same from command line:

bash -x /home/tracker/prod/MMExe 1> /home/tracker/prod/MMExe.log 2>&1
0
 
mw-hostingAuthor Commented:
If I don't put it in quotes i get a ambiguous redirect error.
0
 
mw-hostingAuthor Commented:
I am also able to run this from the command line and it works.

When I run it manually, this is the error I get in the log file
/home/tracker/prod/SSCCMMExe: /home/tracker/prod/SSCCMMExe: cannot execute binary file
0
 
omarfaridCommented:
if you remove the -x and run from the command line what do you get? Also, did you try to see if it requires some env variables to be set? What are the permissions on the file

/home/tracker/prod/SSCCMMExe
0
 
mw-hostingAuthor Commented:
I still get the same error:

/home/tracker/prod/SSCCMMExe: /home/tracker/prod/SSCCMMExe: cannot execute binary file

The permissions are set to 777.
0
 
omarfaridCommented:
are you sure that this binary file is compatable with your system architecture?

what you get if you run

file /home/tracker/prod/SSCCMMExe

file /usr/bin/ls

0
 
mw-hostingAuthor Commented:
Omar,

As I mentioned in my initial post, the error I get is BAD open((null)) but my customer assures me that it runs as expected and I see a file created in another user's directory after I manually run it so it does work.
0
 
omarfaridCommented:
but it is giving you error! so how do you say that it runs?
0
 
mw-hostingAuthor Commented:
It is generating the files that the client needs.
0
 
omarfaridCommented:
I am still waiting you to run on your system the commands below and post output

file /home/tracker/prod/SSCCMMExe

file /usr/bin/ls

0
 
mw-hostingAuthor Commented:
Here is what I get

file /home/tracker/prod/SSCCMMExe
/home/tracker/prod/SSCCMMExe: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, not stripped


file /usr/bin/ls
/usr/bin/ls: ERROR: cannot open `/usr/bin/ls' (No such file or directory)
0
 
omarfaridCommented:
why it is not able to get /usr/bin/ls?

if you run

which ls

what do you get?
0
 
mw-hostingAuthor Commented:
which ls
alias ls='ls --color=tty'
        /bin/ls


file /bin/ls
/bin/ls: ELF 64-bit LSB executable, AMD x86-64, version 1 (SYSV), for GNU/Linux 2.6.9, dynamically linked (uses shared libs), for GNU/Linux 2.6.9, stripped
0
 
omarfaridCommented:
The above shows that there is no problem in compatibility. One more thing which could be the case:

It could be that this binary file is calling another command on your system (e.g. using system() or similar system call) and this command could be missing from your system or is in different path. you may check with developer to see if this is the case.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.