GOAL: Trigger a script every 15 minutes.
SOLUTION:
Cron = job scheduler in unix-type operating systems
Crontab = Cron Table file that configures shell commands to run on some schedule
STEPS to add script
1. Write & Save a series of linux shell/bash commands to script.sh
nano script.sh
2. Open Cron
crontab -e
2. Select 2 for nano (easiest linux file editor)
3. Add to bottom of file:
#min hour day month weekday command
*/1 * * * * <command>
example
#Run Script.sh Every 15 minutes
#min hour day month weekday command
*/15 * * * * /home/user/script.sh
nano /etc/rsyslog.d/50-default.conf
3. Find the line that starts with: #cron.* Uncomment that line to be:
cron.*
4. Save the file (Ctrl + Z)
5. Restart rsyslog
sudo service rsyslog restart
6. Check cron log file
cat /var/log/cron.log
SOLUTION:
Cron = job scheduler in unix-type operating systems
Crontab = Cron Table file that configures shell commands to run on some schedule
STEPS to add script
1. Write & Save a series of linux shell/bash commands to script.sh
nano script.sh
*PATHS MUST BE ABSOLUTE, (from root, i.e. /home/user/script.sh)*
Relative Paths Will Not Work (i.e. echo "hi" > test.txt;). Must be echo "hi" > /home/user/test.txt;
2. Open Cron
crontab -e
2. Select 2 for nano (easiest linux file editor)
3. Add to bottom of file:
#min hour day month weekday command
*/1 * * * * <command>
example
#Run Script.sh Every 15 minutes
#min hour day month weekday command
*/15 * * * * /home/user/script.sh
*preceding "sh" is not needed before the script path for cron*
STEPS to check cron status/error/log
1. Check if cron is running
sudo status cron
2. Open the system log file (for ubuntu)nano /etc/rsyslog.d/50-default.conf
3. Find the line that starts with: #cron.* Uncomment that line to be:
cron.*
4. Save the file (Ctrl + Z)
5. Restart rsyslog
sudo service rsyslog restart
6. Check cron log file
cat /var/log/cron.log
Also possible to see cron jobs with grep CRON /var/log/syslog
This didn't work for me for Ubuntu 12.04, which is why I wrote this post.
Reference