Home > Web Developing > want another crontab example?

want another crontab example?

March 6th, 2009

In this example I am showing you how to use the crontab in order to reload a fresh copy of a DB at 12 noon and 12 midnight everyday. Lets take a look:

SHELL=/bin/sh

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user command

0 12,0 * * * /usr/bin/mysql -u username -ppassword database_name < ~/backupfile.sql

You can see that I am connecting to mysql with my -u username and -ppassword ( And no, I did not make a mistake by not putting a space in between -ppassword, its supposed to be like that, if you put a space in between it thinks that *space* is part of your password.) and telling it to import the sql file backupfile.sql to the database database_name. This script is good if you need to reload a DB with fresh new data everyday. For example if you have a TEST CRM that people can use and test, you dont want people to input so much junk, so you have to reset the test data ever so often.

I love cron. hes a good friend of mine! :)

Web Developing

  1. Johnny
    July 24th, 2009 at 08:17 | #1

    Awesome… good job explaining this.. its exactly what I was looking for!!

  1. No trackbacks yet.