Cron jobs with node
Cron jobs not working!
Recently I discovered that my cron jobs weren’t working even though I could run the cron job command manually from the command line.
I made my cron entry by opening up my crontab file on my Ubuntu server.
|
|
After reviewing how cron jobs work, I came up with this entry:
This of course was the job that wasn’t working. There are two problems.
1. The script needs to be executable.
Here are the permissions for my script:
Notice that nobody has permission to execute the script. We need to add that in. So I added deployment task (in capistrano) to make the script executable.
Now my permissions are correct:
2. The executable path for node
needs to be explicit
When the cron job attempted to run the node
command was unable to be found. We need to include the full path.
We can find the full path with the which
command:
With that knowledge we can update our script.
Here is my new cron entry:
More Info
Cron jobs are logged in the syslog
But I want some more info. By outputing data as my script runs, I can feed useful information to a log file.
Here’s my final cron entry with my log file in place:
Cron jobs are now working as expected!