Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

When I run a script manually using root it is working fine. when I execute the same script inside cron it is not running. I checked the cron is actually calling the script but the script is not executing. I exported the output of echos in the script to the text file but the text file is didn't logged anything. Please check this cron

*/10 * * * *  sh /var/www/sym_monitor/restart.sh > /var/www/migrate/root_restart.txt
share|improve this question
    
Try: /bin/sh -c '/var/www/sym_monitor/restart.sh > /var/www/migrate/root_restart.txt' or simply: /var/www/sym_monitor/restart.sh > /var/www/migrate/root_restart.txt. You may have to set the executable bit of restart.sh for the latter to work. –  jaume Feb 14 '13 at 11:53
    
Change > to &> to log error messages as well. If that doesn't help, could you post the shell script? –  Dennis Feb 14 '13 at 13:20

2 Answers 2

The cron entry is correct only if you're using crontab -e to add it. If you add it directly to /etc/crontab you need to include the user name to run it under.

The cron should spool to /var/spool/cron/ if successfully created.

Check the script permissions, chmod +x.

It's good practice to include the full path to the shell, /bin/sh, or just exclude it altogether.

*/10 * * * * /bin/sh /var/www/sym_monitor/restart.sh > /var/www/migrate/root_restart.txt

Also, are you including the shebang line in the script? It should start with #!/bin/sh or #!/bin/bash

share|improve this answer
    
And it is a good idea to give the full path to any executables called, and files used. –  vonbrand Feb 15 '13 at 3:22

Try adding the following to end of your crontab line:

 2> /var/www/migrate/error.log.txt

Now for a couple of conjectures (you might have added the scripting to the question, if it not too long):

Check in your scripting to see if you have a line settine the PATH variable to the same thing that you have when you do:

 echo $PATH

Remember that things started in cron do not execute any of the shell initialization files that happen when you login.

Are you sure that the file has at least READ permission....a shell script needs more than simple EXECUTE permission. You might have included a ls of the file too.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.