I’m looking to get a cronjob set up on my new EC2 instance.
First off, I’m using Ubuntu 12.04. Secondly, it’s a default installation so I’m going to show you where all the default shit is.
Ok, so with any piece of tech your working with, the first thing you should do is figure out how to log output. On Ubuntu 12.04 everything for crontab gets logged to /var/log/syslog…so you’ll want to search that for cron entries when something doesn’t work:
less /var/log/syslog | grep CRON
Let’s get started the first thing we need to do is edit the crontab. There’s a brief explanation of the syntax here: http://www.adminschoice.com/crontab-quick-reference/
I’m starting out running my process every minute, then I’ll set the correct time settings when I’m sure everything is working. Start by doing this:
Now inside of crontab, initially I’m going to do something every minute. To do this, follow the syntax below:
* * * * * /usr/bin/curl -o /home/ubuntu/logs/temp.txt http://localhost/app/update/update.php
Now we can see an output happening at /home/ubuntu/logs/ where a file named temp.txt is being placed with the output of the file.
If you arent seeing this output try adding “>/dev/null 2>&1” to the end of the line so ubuntu doesn’t try to email the output of the cron to you. This might mess some stuff up. Your new command would be like this (notice I also changed the cron timing to be what I want, in this case, 3AM every day):
0 3 * * * /usr/bin/curl -o /home/ubuntu/logs/temp.txt http://localhost/linkedin/update/update.php >/dev/null 2>&1
That’s it, have fun!