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
  • 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.)......
  • Scheduling tasks in linux kcron I don't know if kcron deserves a seperate entry for scheduling tasks under linux. Cron is what I typed on last time and it's the daemon that controls scheduled tasks. The method for scheduling tasks that I went through last time is for the command line. Like many things in......
  • Remote tech support with anything - would I do it? I've tried to ask myself if I'd trust someone enough to let them run a remote session on my own desktop to solve a problem. I think the answer is "it depends". If you think about it, I do tech support for home users quite a bit and they let......
Blog Traffic Exchange Related Websites
  • Should You Rent or Buy a Home in Retirement? Rent or buy? This is a question that is taking on more significance for those of us preparing to retire. Owning your own home in retirement used to be an assumed goal. That was when having paid off your mortgage was also assumed. No more. Many boomers are still lurching......
  • Using a Vacation Home for a Vacation A new word added to our recession vocabulary is "staycation" which translates to "taking a vacation at home." The word may be new but the concept isn't. Vacation home owners have been taking staycations for years. Isn't that the purposes of owning a second home? There is nothing disappointing or......
  • Preparing to Refinance When I purchased my new home about a year ago, I went with the builder's preferred lender because of the lower closing costs with the incentives. Because I also hadn't yet sold my prior home and really had no cash to put down, I did 100% financing with an 80/20......
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