TF-1 Technology Blog

Posted: May 18th, 2012 by Hans Lee

A webmaster’s day may involve doing a series of repeated tasks, like checking servers’ vital statistics, rotating server access logs, gathering visitor data and what-nots. To keep things simple and in control it is essential to use cron to manage these tasks. What it does is this daemon will perform tasks according to the times specified. To start assigning cron jobs to linux systems you enter crontab -e. Usually the format is like below:

* * * * * command

The 5 asterisks specifies in order the minute, hour, day of month, month, and day of week of which the command will be run. So if I want to run a script that rotates server logs on every sunday at 3:30am then I’ll make a call like this:

30 3 * * 0 /path/rotate_logs.sh >> logs.log 2>&1

The latter part of the line specifies that I want all the script output and error messages to be logged into logs.log, which will be a piece of useful information when things go wrong.

What about commands that requires to be run more frequently? Say we need to run a script that checks a server’s well-being every 3 hours, you can set the cron job up like this:

* 0,3,6,9,12,15,18,21 * * * /path/check_well_being.sh >> wellbeing.log 2>&1

Alternatively, you can also set it up like this:

* */3 * * * /path/check_well_being.sh >> wellbeing.log 2>&1

The only difference from these two ways is that cron will only make sure the command is run every 3 hours, but not necessarily on 3, 6, 9, and 12 o’clocks of the day.

When you finish editing, save the cron job, and check it by entering crontab -l, if everything is right then the cron jobs will start running those commands by itself.

Comments are closed.

several months ago: TF-1 marks the successful engagement of 500 #Drupal projects, from which over 100 are Drupal #Commerce and Drupal #Ubercart specific. Reply Retweet Favourite
several months ago: At the new office, TF-1 Team @ work http://t.co/B0p9eR23 Reply Retweet Favourite
several months ago: We just started listing our Thrinacia pledgers. Check it out at https://t.co/ZLFfAfbZ Reply Retweet Favourite
several months ago: Taskforce-1 is now a seed partner of NCFA. http://t.co/fvkNHT1R Reply Retweet Favourite
several months ago: Article on Thrinacia, our open source SaaS crowdfunding platform just got published on NCFA Canada at http://t.co/xuk2DTZv Reply Retweet Favourite
several months ago: Several new pledges received for Thrinacia initiative today, thank you everyone and lets raise enough to complete Milestone 2. Reply Retweet Favourite
Contact Us




TaskForce-1 Industries Ltd.
#110 - 19162 - 22'nd Av.
Surrey, B.C - Canada
V3S 3S6 View Map
Toll Free Phone: 1.888.630.5733