Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
Is this the entire line? (If so, it's missing a time spec, telling cron to run it every minute, see man 5 crontab) If not, what is the line you inserted into your crontab? – sr_ Dec 5 '11 at 10:32
@sr_ sorry, sure I have 5 *'s at the beginning. – mustafa Dec 5 '11 at 10:34
Do you see any cron report mail in your local mailbox? It might contains some error messages there. – number5 Dec 5 '11 at 10:38
no, there are no mails and logs :( – mustafa Dec 5 '11 at 10:45
I have seen that it's working after a reboot. (don't know why) And it's working only when the user is logged in. But I supposed that it should be working when the user is not logged in too. Right? – mustafa Dec 5 '11 at 10:47

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:

  PATH=<Path Var of The Running user>

See also man 5 crontab for further descriptions.

share|improve this answer
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 5 '11 at 12:08
@Nikhil there are no logs :( it's Angström Linux, how can I enable logs? – mustafa Dec 5 '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 6 '11 at 4:57

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.

share|improve this answer

Your Answer


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.