Solved

Cron errors with : No such file or directory

Posted on 2009-04-09
31
568 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:mw-hosting
  • 13
  • 9
  • 5
  • +2
31 Comments
 
LVL 7

Expert Comment

by:martin_2110
ID: 24110043
Try running dos2unix on it.
dos2unix file_name
0
 
LVL 7

Expert Comment

by:martin_2110
ID: 24110050
if it is bash you can run it with bash -x to debug. or perl -d if its perl.
0
 

Expert Comment

by:mister2walker
ID: 24110068
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
 

Author Comment

by:mw-hosting
ID: 24110116
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
 
LVL 7

Expert Comment

by:martin_2110
ID: 24110125
can you send the output of bash -x /home/john/scriptfile
0
 

Author Comment

by:mw-hosting
ID: 24110153
I get an error: Cannot execute binary file.

0
 

Expert Comment

by:mister2walker
ID: 24110162
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
 

Expert Comment

by:mister2walker
ID: 24110216
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
 

Expert Comment

by:mister2walker
ID: 24110336
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
 

Author Comment

by:mw-hosting
ID: 24111146
It's a binary file so I don't think any of this will work.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24111956
check if there are env variables that should be set
0
 

Author Comment

by:mw-hosting
ID: 24112805
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24112855
env variables are not loaded when you run crontab jobs, you should set them in the script
0
 
LVL 29

Expert Comment

by:fosiul01
ID: 24114142
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
 

Expert Comment

by:mister2walker
ID: 24114801
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 

Author Comment

by:mw-hosting
ID: 24115680
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24115713
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
 

Author Comment

by:mw-hosting
ID: 24115745
If I don't put it in quotes i get a ambiguous redirect error.
0
 

Author Comment

by:mw-hosting
ID: 24115756
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24115794
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
 

Author Comment

by:mw-hosting
ID: 24116059
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24116255
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
 

Author Comment

by:mw-hosting
ID: 24116293
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24116642
but it is giving you error! so how do you say that it runs?
0
 

Author Comment

by:mw-hosting
ID: 24116744
It is generating the files that the client needs.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24117207
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
 

Author Comment

by:mw-hosting
ID: 24117300
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24117370
why it is not able to get /usr/bin/ls?

if you run

which ls

what do you get?
0
 

Author Comment

by:mw-hosting
ID: 24117386
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
 
LVL 40

Expert Comment

by:omarfarid
ID: 24117448
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
 

Accepted Solution

by:
mw-hosting earned 0 total points
ID: 24278125
Issue has been resolved by adding 2> /dev/null & to the end of the line.
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now