Scheduling tasks in linux cron



Windows has scheduled tasks which most people are only halfway aware of. Linux has very powerful scheduling capabilities coming from it’s unix heritage. cron is the daemon that deals with scheduled tasks under most linux distributions. There are a couple ways that you can schedule cron tasks. The first is from the command line.


Open a console and become the user that you want to schedule tasks for.

Now type crontab -e

This brings up the editor for your crontab or your cron table, which is a list of commands to run and times to run them.

If your new to vi this can be frustrating, vi is the default text editor for most distributions. *(I’ve seen pico in some places.) If it’s pico you can start typing with no problems, if it’s vi, you’ll need to press the insert key first (or the letter i)…

Anyway, if you don’t have any scheduled jobs you’ll start out with a blank slate…

The format for entries is something like this…

00 14 * * * /home/userdir/scripts/starttunnel

The first 5 columns control WHEN a job runs. the first column is minutes, the second hours, the third is the day of the month, the fourth is for the month of the year and the 5th column is for the day of the week. After that you can enter the absolute path to the command or script that you want to run. Asterisks mean to match anything, so the above runs EVERY day at 14:00 hours *(2PM)

Let’s say, I want the above script to run at 12:36 PM on July 3rd each year…
36 12 3 7 * /home/userdir/scripts/starttunnel

As for the days of the week, 0 and 7 both refer to Sunday, 1 is Monday, 2 Tuesday, 3 Wednesday, 4 Thursday, 5 Friday and 6 Saturday… So we could make the above run only for those years where July 3rd is a Friday by doing this…

36 12 3 7 5 /home/userdir/scripts/starttunnel

Multiple run times are fairly easy too… Let’s say we want the script to run every thirty minutes…

0,30 * * * * /home/userdir/scripts/starttunnel

This one runs at 0 and 30 of each hour every day. If you’re using vi, you’ll need to press escape, then :wq (colon followed by wq) and enter to write and quit. Under pico ctrl-o to write the file and ctrl-x quits.

Related Posts

Blog Traffic Exchange Related Posts
  • Remote Tech Support with x11vnc and wrapper script So, the idea is that I wanted something "like" the Ultranvnc Single Click download, only for linux. The main idea being is that if someone is looking for a bit of desktop tech support on linux, we don't need to be giving instructions for 5 different package managers, or source......
  • The Cost of Running a PC 24 Hours a Day I saw an interesting question over at slashdot on the topic of how many companies actually had their employees power down their PC's overnight. The site in question had about 8000 PCs about half of which stayed powered on overnight. There's a lot of talk these days about "going green".......
  • Considerate Computing This may cover a fair amount of ground, but here goes.... Today I was looking at a system to see just what software was in use, evaluating the possibility of linux as a replacement. Office, of course was a must (at least the ability to read .doc and .xls files.)......
Blog Traffic Exchange Related Websites
  • Do not try this at home. I was aiming for 16 miles today, and planned to get moving as close to 5:30 as possible. Instead, I intentionally disabled my 5:30 alarm at 5:15 and then woke up just before my 6:30 alarm. I ate one of those Little Debbie Brownie things for pre-run fuel. Awful nutrition,......
  • Is there life after DNF? - a partial-race report [/caption] Race Preparation: Something about this morning's race just wasn't right. There were just other priorities going on this week, starting with the night of Thunder Over Louisville and every night up until last night, I had been up late with kids who had stomach bugs, or just going to......
  • How to Pick the Right Air Conditioning System for Your Home Thankfully, today we have many options when it comes to cooling our homes. If you are wondering if it is time to upgrade to a new kind of cooling system, you’re going to have a lot of options. However, they may not all be as effective for your particular needs.......
www.pdf24.org    Send article as PDF   

Similar Posts


See what happened this day in history from either BBC Wikipedia
Search:
Keywords:
Amazon Logo

Comments are closed.


Switch to our mobile site