Skip to content
Advertisement

why crontab run my shell script successfully but failed to start my binary file program?

i made a shell script like the following:

#!/bin/bash

/root/bin/mybin >> a.log

then I use crontab to start it at a fixed time. The result is:

  1. crontab run this script(a.log exsited and i can see the log from /var/log/cron , also it shows crontab run it)
  2. but mybin is not running (mybin is a while(true) loop program)

I can run the script manually from the linux shell.

And I am sure it is not related to user access problems, since i use it as Root.

Using the command

strace -f -o /tmp/data.log ~/deploy/StartData.sh >> ~/script-log/data.log

the strace output contains

7011 write(2, "/root/deploy/StartData.sh: line "..., 80) = 80 
7011 write(2, "/root/deploy/StartData.sh: line "..., 82) = 82 
7011 exit_group(2) = ? 
7011 +++ exited with 2 +++ 

These are the last messages of /tmp/mybin.trace, besides these, no error message

That really bothers me, Any Suggestions are great to hear.

Advertisement

Answer

The output from strace shows that errors occur in a shell script /root/deploy/StartData.sh, and the shell exits with exit code 2.

7011 write(2, "/root/deploy/StartData.sh: line "..., 80) = 80 → error message with file name and (probably) line number
7011 exit_group(2) = ? → program exits with code 2 (probably an error indication)

According to a reference of shell exit codes this might mean

Misuse of shell builtins (according to Bash documentation)

Your program/script seems to have a problem when it’s run from cron. Possible reasons might be:

  • The script doesn’t have an associated terminal.
  • The script is run in a different directory.
  • (probably more)

For a better answer follow the hints in the comments.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement