Why are my cron jobs not working in Ubuntu?

Why are my cron jobs not working in Ubuntu?

Cron jobs won’t run if your user’s password has expired. One indication of this is if your cron log (typically /var/log/syslog on Ubuntu, I believe) contains messages like “Authentication token is no longer valid; new one required”. You can check for this problem by running sudo chage -l the_username. Here’s an example of an expired password:

How often do you need to run a cron job?

To run every minute you would need to use * * * * * (“every minute” instead of “1st minute”). Kudos to @KeithThompson for pointing this out. The granularity of cron is one minute. If you need to run a job more frequently than this you may want to consider either a standalone daemon, or two lines in cron one of which is preceded by sleep 30.

What should I do if my Cron script is not working?

Consider what happens if you want to run your script on a different system, and on that system, the command is in /opt/someAppv2.2/bin instead. You’d have to go through the whole script replacing /opt/someApp/bin with /opt/someAppv2.2/bin instead of just doing a small edit on the first line of the script.

What’s the difference between a cron and a crontab file?

The cron job specification format differs between users’ crontab files (/var/spool/cron/username or /var/spool/cron/crontabs/username) and the system crontabs ( /etc/crontab and the the files in /etc/cron.d ). The system crontabs have an extra field ‘user’ right before the command-to-run.

Why are crontab scripts not working in Ubuntu?

The default path is usually /bin:/usr/bin so only standard commands will run. These directories usually don’t have the desired command. This also affects scripts using non-standard commands. Other environment variables can also be missing. Clobbering an existing crontab entirely has caused me problems.

Why is the PATH variable not working in Cron?

It’s worth noting that variables from /etc/environment will be passed on to cron jobs, just not the variables cron specifically sets itself, such as PATH. To get around that, just set your own PATH variable at the top of the script. E.g. Some prefer to just use absolute paths to all the commands instead.