1

I have a program written in C with OpenCV. It captures an image from the webcam and saves on the disk with the name given as an argument. I want to trigger it every minute, thus I inserted the following line to crontab.

* * * * * /home/mustafa/Desktop/capture2/capture2 `date +\%y\%m\%d\%H\%M` >> /home/mustafa/Desktop/webcam.log

This command runs as expected when I run it from the console. But it is not triggered by crontab.

Are there any errors in my crontab syntax?

Edit: it's Angström Linux

mustafa
  • 221
  • 3
  • 9

3 Answers3

1

Sometimes the commands inside the script depend on the PATH environment variable of the running user.

Try to add the PATH env var at the beginning of this crontab, This could also a problem with the proper shell in use. Especially on actual debian systems the standard shell /bin/sh links to /bin/dash and not to /bin/bash. You can fix that with the correct shebang in your script or change the SHELL env var for your crontab processes at all:

  SHELL=/bin/bash
  PATH=<Path Var of The Running user>

See also man 5 crontab for further descriptions.

f4m8
  • 1,989
  • 1
  • 11
  • 5
  • What do the errors say in logs, /var/log/cron or /var/cron/log

    Check if the cron is allowed for the users if the file exists /etc/cron.allow (or /etc/cron.deny)

    – Nikhil Mulley Dec 05 '11 at 12:08
  • @Nikhil there are no logs :( it's Angström Linux, how can I enable logs? – mustafa Dec 05 '11 at 21:14
  • check /etc/syslog.conf or /etc/rsyslog.conf and find where the cron logs are getting redirected. Check if the crond service is running. – Nikhil Mulley Dec 06 '11 at 04:57
0

In order to activate error logging specifically for this crontab entry you can redirect the error to a file.

* * * * * /home/mustafa/Desktop/capture2/capture2 `date +\%y\%m\%d\%H\%M` 1>>/home/mustafa/Desktop/webcam.log 2>>/home/mustafa/Desktop/error.log

1>>/home/mustafa/Desktop/webcam.log appends the output from the script to the file webcam.log

2>>/home/mustafa/Desktop/error.log appends the error from the scripts to the file error.log

A few things that we need to take care of before executing a script from the crontab,

  • The user who has the crontab entry to execute the script should have access to all files that are being used by the script, including execute permissions to the script file. For files where the script is writing/appending, the user should have write permissions.

  • All paths in the script file should be absolute paths. Preferably set variables in the start of the script that stores the path to the files.

After you have checked the above two points, try executing the script using crontab, and check the error.log file for errors. Depending on what errors you have there, you can make appropriate changes to your script.

debal
  • 3,704
0

As suggested by gelraen and uniomni in this thread, try adding a new line to the end of your crontab. Apparently some cron implementations do not pick up anything in the crontab following the last newline character. I just had this problem on a RedHat 6 box, and now all of my jobs run as intended.

Ubunfu
  • 101