If you’ve used Linux for a while you’ve probably learned about cron, which is the system service responsible for executing scheduled tasks. Cron runs in the background, and helps keep your computer running. At scheduled times, it launches programs to rotate log files, check for software updates, and perform other housekeeping jobs. You can also use cron to your own advantage and to schedule your own tasks; for example, a routine backup of your home directory, or to check if you have new mail. The easiest way to schedule tasks in Ubuntu or Fedora is to use the gnome-schedule application. This tutorial will show you how to schedule tasks using the Gnome Scheduler, a graphical front-end for cron.

Installation

First, install the gnome-schedule application. As usual, this is a quick one-liner in most popular distributions:

Once it’s installed, you should see a new “Scheduled Tasks” application in the System Tools menu.

New and existing tasks

The task scheduler gives you three options for creating a new task. You can chose a recurring task, which is the primary use of gnome-schedule as a frontend for cron. It also allows you to create a task that runs only once; this actually uses the at service.

Additionally, you can create custom schedule templates; for example, if you want to run tasks on certain holidays, you can create a template for that so you don’t have to re-create the cron rules each time. Most users won’t need this feature, but it’s nice to have.

The main window shows you the currently-scheduled tasks:

It’s a bit spartan, and there’s definitely no eye candy, but if you’re at all familiar with cron you’ll be very comfortable with the output.

Scheduling a task

The primary use of gnome-schedule is to setup cronjobs, and it does it very well. The single-window configuration allows you to specify a name for the job as well as the command to run. The date and time wizard accepts standard cron syntax, but a major feature is a GUI tool that sets up the schedule for you.

For example, by choosing whether you want to run a task every day, every X number of days, or in a range of specific days, you are able to set a schedule with a very high level of precision. This is the precision that cron is known for, and using gnome-schedule you are able to take this power and implement it via a convenient graphical interface.

Creating a one-time-only task

Gnome-schedule can create one-time jobs, in addition to recurring tasks. Creating a single-instance job actually uses the at daemon rather than cron (advanced users should be familiar with the difference, but from our current perspective it doesn’t matter). When you create a one-time job, you get a simple window to give the job a title and a time to launch, and to say what commands you want to run at the scheduled time.

In the above screenshot, I am creating a scheduled task to pop up a reminder window (using Zenity) at 11:55 to tell me that I need to post something to TechThrob (although I assure you, I don’t need any reminders for that). Of course, you can use this for anything — you might want to schedule an alarm to wake you up in the morning, or a reminder to pick something up on the way home.

I find that the single-instance scheduler is actually incredibly useful, perhaps even more useful that the repeating schedule. I never really used at when it was just a command line utility; I knew it was there, but I didn’t see a need for it. Once I started using gnome-schedule, though, I found that scheduling reminders and automated jobs was very easy and incredibly useful.

Very useful help

The scheduler is incredibly well documented, and you can read the help by clicking the gnome help icon in the main window. I ran into a small problem trying to get graphical applications to launch (zenity, in the above example), but I quickly found the answer in the help (you have to specify the DISPLAY variable). If you’re curious as to how something works, or you’re having some problem, I suggest giving the documentation a look before you get frustrated or ask for help.

What do you schedule?

Have you ever used cron before? What kind of tasks do you have automated with cronjobs? I’m also curious to know if others find the cron syntax as confusing as I do – I’ve always had to lookup cron syntax when I need to do something more complicated than setting a task to run at a specified minute or hour (hence why I love gnome-schedule’s GUI so much!). Leave your thoughts in the comments below!

We use cron heavily (the crontab is about 29k long) at this single-parent household. Things like X10 lights off / on according to our schedule; WAV and mp3 chimes and alarms to get us up in the morning on time (and say that it’s time for bed); turning Net access on and off on kids’ machines with firewall rules (so they’ll actually go to bed), even something to chime the hour late at night… And then the usual stuff of automating backups, mail-fetches, mail-sends, webcomix fetches…

On our DSL line it takes maybe 2 hours to fetch in an iso image. If you schedule that for late at night, an amazing thing happens: nobody complains about “somebody dropped a brick on the Net”, because nobody’s online when wget fetches in that iso. I solved that with two scripts: one does wget fetches of a __DATA__ list of isos; the other, driven by cron, checks a timestamp to decide if that ‘get’ script has any recent edits and should be run, then updates the timestamp. Result: a get session runs late at night, but only tries to fetch a given iso once through (wget uses the -c arg so it can pick up where it’s left off).

Cron and at are great for machine-style scheduling. Where they’re not so great is for people-style schedules. Things like recognizing Columbus Day as a school holiday in the US (so the wakeups should be on the holiday schedule, not the schoolday one), and properly setting “first Thursday of the month” type events, and accounting for Yule, winter and spring vacation weeks. I’ve played around with a front end that’ll take in those kinds of events and generate a normal crontab, but it’s slow going (because for some reason my kids want my attention, and, they being my priority, they get it).
If someone picks up the idea and runs with it, I’ll be pleased: a script that runs once a night, at or just after 00:00, converting a more people-oriented schedule to the crontab that’s needed to fulfill that for just the coming day, which is then fed to cron. Maybe an ical-to-cron converter, or something based off the KDE kalendar.

Wow! That’s the most personalized use of cron-based scheduling I’ve heard of so far. Sounds like you’ve got your household pretty well automated; I’m sure this must save you a lot of time.

I also like your idea about having something download very late at night when no one else is online; if you don’t need something right away, this is pretty smart. I’ve used cron to automate backups late at night, but it makes sense to use it in the other direction as well.

Saving time is good; saving trouble from missed events is more important. I’m as distractable as my kids; barring power glitches, the computer isn’t.

This means that, even if I forget to set the alarm clock, the kids won’t be late to school, because the computer will have the lights on a few minutes before zero-hour, and fast rock or thrash metal playing (the kids endured years of Metallica’s ‘Enter Sandman’ before I took the time to write a random tune-selector script for that time-slot) when it’s time to get up. ‘Take the trash out’ Xdialog messages pop up on trash days, along with a noise so it’s noticed; ‘take the meds’ msgboxes pop up at the right hours (and stay onscreen until dismissed, so there’s no missed-dose questions); the chimes even remind me when it’s time to actually get up from the console and go fix dinner for us.

It doesn’t mean we’re getting automated; it means that, with computer help, we got reliable, and that’s a good thing.