4

I'm using Ubuntu Linux 10.0.4. I want to run a script every 6 hours, every day. When I issue sudo crontab -e, I see:

# m h  dom mon dow   command
* 00,06,12,18 * * * /opt/scripts/selenium/run_nis_inf_tests.sh

However, I'm not seeing the expected outcome from my script, and I'm not even sure if its running. Is there a way to test, short of waiting until the specified time, that the script is running properly. Or, how can I view the errors the script is generating? - Dave

Mike Pennington
  • 41,899
  • 19
  • 136
  • 174
Dave
  • 8,667
  • 25
  • 72
  • 90
  • You should also take care about the cronjob's filename and avoid underscore or extensions. For example on the Ubuntu mother (eg Debian), I faced that issue as described [here](http://stackoverflow.com/questions/5486601/linux-debian-crontab-job-not-executed). – hornetbzz May 01 '11 at 18:53

2 Answers2

5

You can update the MAILTO variable to your email address, and cron should email you any STDOUT and STDERR output. Also check your syslog file /var/log/messages to see if the script is being executed by cron.

-Tony

Alpha01
  • 820
  • 1
  • 7
  • 16
  • Is there always a success/failure message written to /var/log/messages? If so, it contains nothing about my cron, which would indicate it isn't running. I haven't got email set up on my machine yet, so I'll give that a go and see what shakes out. – Dave May 02 '11 at 14:38
  • There is nothing written to /var/log/messages but adding a MAILTO variable above the crontab line gives the feedback I was looking for. - Dave – Dave May 04 '11 at 14:23
  • in a debian system the default log is /var/log/syslog – DeveloperChris Feb 26 '19 at 00:24
1

Cron should mail it results so it looks like you have a problem. Here, it seems you are missing a user to run the script as :

00,06,12,18 * * * user_name /opt/scripts/selenium/run_nis_inf_tests.sh

replace user_name by the name of the user the script needs to be run by, verify permissions of "run_nis_inf_tests.sh" and you should be ok.

mecano
  • 59
  • 2
  • When I tried your suggestion (adding the username), I got the error, "/bin/sh: selenium: not found". The syntax I use is, "00 */1 * * * /opt/scripts/selenium/run_nis_inf_tests.sh". – Dave May 04 '11 at 15:35
  • Yes sorry, no username needed in your case as you do crontab -e ! Did you check syslog.conf ? – mecano May 05 '11 at 09:37