The basics of crontab -e, Cron Job Tutorial
Credit for this tutorial goes to Rodrigo Caffo and John Chase for giving me clarification (as a newbie) at running some new commands with ssh.
Rodrigo is a whiz with Ruby on Rails and cron and John a command line guru.
This is a basic tutorial on finding cron jobs and moving them from one server to another:
We recently needed to move a database backup script to a new server after migrating the website, application and database. This is a quick tutorial on the steps to migrate the script.
1. Since I didn't know where the last developer wrote the cron job - I look it up using the crontab command. To see the cron jobs on the server run:
crontab = where the crons run
-e = indicates we want to edit the crons
In this example we see the output of the crons running:
59 * * * * /db/backup.sh
*/15 * * * * /usr/local/cpanel/whostmgr/bin/dnsqueue > /dev/null 2>&1
2,58 * * * * /usr/local/bandmin/bandmin
0 0 * * * /usr/local/bandmin/ipaddrmap
54 0 * * * /usr/local/cpanel/whostmgr/docroot/cgi/cpaddons_report.pl --notify
47 5 * * * /scripts/upcp
0 1 * * * /scripts/cpbackup
0 9 * * * RAILS_ENV=production /home/wwwluna/crm/script/runner 'WorkOrderMailer\
0 6 * * * /scripts/exim_tidydb > /dev/null 2>&1
*/5 * * * * /usr/local/cpanel/bin/dcpumon >/dev/null 2>&1
2. Now we recognize one of the scripts "59 * *..." - but want to see what it is. So we run the command "cat" with the path which shows the output of the file.
In this example we run:
The output of the file shows we have a backup script saving to the server with a command sending a .gz file of the database to email user "shad (at) lunawebs.com":
root@luna [~]# cat /db/backup.sh
SUBJECT="ESS db backup "`date`
RCPT="shad (at) lunawebs.com"
mysqldump -u essyenv_user -pamb13t3n! essyenv_main > /db/$FILENAME
/bin/mime_mail -s "$SUBJECT" -u "$RCPT" -f "/db/$FILENAME.gz"
3. We want to see how many backups are currently on the server. We run another command.
To see the backups in the db folder with gz compression run:
4. Now we just port the entire /db/ directory to the new server and the line 59 * * * * /db/backup.sh we add to crontab (using crontab -e)
We should have mysqldump in our path and /bin/mime_mail available