Technology

at, batch and cron

Posted on June 17, 2010 at 10:00 pm

This was first published in Linux Journal, issue 184.

at,batch,cron – The ABC’s of doing work when nobody’s home

People have always been interested in doing more work with less effort. This drive kind of reaches its peak when work is being done, even though you aren’t actually doing anything. With Linux, you can effectively do this with the trio of programs at, batch and cron. So now your computer can be busy getting productive work done, even long after you’ve gone home. Most people have heard of cron, fewer people have heard of at, and even fewer have heard of batch. Here you’ll find out what they can do for you, and the most common options to get the most out of them.

at is actually a collection of utilities. The basic idea is that you can create queues of jobs to run on your machine at specified times. The time at runs your job is specified on the command line, and almost every time format known to man is accepted. The usual formats, like HH:MM or MM/DD/YY, are supported. The standard POSIX time format of [[CC]YY]MMDDhhmm[.SS] is also supported. You can even use words for special times, like now, noon, midnight, teatime, today or tomorrow, among others. You can also do relative dates and times. For example, you could tell at to run your job at 7PM in 3 days time by using “7PM + 3 days”.

at will listen to the standard input for the commands to run, which you finish off with a ctrl-D. You can also place all of the commands to run in a text file and tell at where to find it by using the command line option “-f filename”. at will use the current directory at the point of invocation as the working directory.

By default, at will dump all of your jobs into one queue named “a”. But you don’t need to stay in that one little bucket. You can group your jobs into a number of queues quite easily. All you need to do is add the option “-q x” to the at command, where “x” is a letter. This means that you can group your jobs into 52 queues (a-z and A-Z). This lets you use some organization in managing all of this after hours work. Queues with higher letters will run with a higher niceness. The special queue “=” is reserved for jobs currently running.

So once you’ve submitted a bunch of jobs, how do you manage them? The command atq will print out the list of your upcoming jobs. The output of the list is: job ID, date, hour, queue and username. If you’ve broken up your jobs into multiple queues, you can get the list of each queue individually by using the option “-q x” again. If you change your mind, you can delete a job from the queue by using the command “atrm x”, where x is the job ID.

Now, what happens if you don’t want to overload your box? Using at, your scheduled job will run at the assigned time regardless of what else may be happening. Ideally, you would want your scheduled jobs to run only when they won’t interfere with other work. This is where the command batch comes in. batch behaves the same way at does, but will only run the job once the system load drops below a certain value (usually 1.5). You can change this value when atd starts up. By using the command line option “-l xx”, you can tell batch not to run unless the load is below the value “xx”. Also, batch defaults to putting your jobs into the queue “b”.

These tools are great for single runs of jobs, but what happens if you have a recurring job which needs to run on some sort of schedule? This is where our last command, cron, comes in. As a user, you actually don’t run cron. You instead run the command crontab, which lets you edit the list of jobs that cron will run for you. Your crontab entries are lines containing a time specification, and a command to execute. For example, you might have a backup program running at 1AM each evening:

0 1 * * * backup_prog

cron will accept a wide variety of time specifications. The fields available for your crontab entries include

field allowed values
minute 0-59
hour 0-23
day of month 1-31
month 1-12
day of week 0-7

Using these fields and values, we can use them directly, use groups of values separated by commas, use ranges of values, or use an asterix to represent any value. You can also use special values

string meaning
@reboot run once, at startup
@yearly run once a year (0 0 1 1 *)
@annually same as @yearly
@monthly run once a month (0 0 1 * *)
@weekly run once a week (0 0 * * 0)
@daily run once a day (0 0 * * *)
@midnight same as @daily
@hourly run once an hour (0 * * * *)

Now that you have these three utilities under your belt, you can schedule those backups to run automatically, or get a long compile to start after you’ve gone home, or get your machine to keep using up any idle cycles. So go out and get lots of work done, even when nobody is home.

fvwm-crystal and python

Posted on March 2, 2010 at 11:42 pm

I’ve just started playing around with fvwm-crystal on Ubuntu, and I’ve run into an issue that others may have, too. Out of the box, I didn’t have any application menus showing up. It turns out that fvwm-crystal is sensitive to what version of python you are running on your system. Once I changed the symbolic link /usr/bin/python to point to /usr/bin/python2.5 rather than /usr/bin/python2.6, all of the scripts to generate the application menu worked. This should be stated somewhere in the documentation. If you run into this issue, you can simply delete the old symlink with

sudo rm /usr/bin/python

and create a new symlink with

sudo ln -s /usr/bin/python2.5 /usr/bin/python

Hopefully this helps other people in the same boat.

Open Circuits

Posted on September 21, 2009 at 11:06 am

Open Circuits provides a site full of ideas and circuits put into the open source community. Using their description:

Open Circuits is a wiki for sharing open source electronics knowledge, schematics, board layouts, ports and parts libraries. This include open hardware Music Players, atomic microscopes, PC, PDA and mobile phones, and batteries.

Visit, and add what you can.

Perma-tech

Posted on May 18, 2009 at 10:35 pm

You’ve likely heard of permaculture before. This is the philosophy of agriculture which is capable of being permanent. The idea is that you plant your crops and care for your soil so that it can be sustained indefinitely. I think that it is time for us to start thinking the same way about our technology. A kind of permatech.

The beginnings of a movement are starting to form. An example is the repair manifesto. The idea here is that we should look at the items that we purchase and use in our day-to-day life, and choose items that can be repaired. If an item cannot be repaired, we are effectively just renting the item. When it finally does break, or wear out, we have no choice but to dump it in the trash and get a new one. The manifesto itself is:

  1. Make your products live longer!
    Repairing means taking the opportunity to give your product a second life. Don’t ditch it, stitch it! Don’t end it, mend it! Repairing is not anti-consumption. It is anti- needlessly throwing things away.
  2. Things should be designed so that they can be repaired.
    Product designers: Make your products repairable. Share clear, understandable information about DIY repairs. Consumers: Buy things you know can be repaired, or else find out why they don’t exist. Be critical and inquisitive.
  3. Repair is not replacement.
    Replacement is throwing away the broken bit. This is NOT the kind of repair that we’re talking about.
  4. What doesn’t kill it makes it stronger.
    Every time we repair something, we add to its potential, its history, its soul and its inherent beauty.
  5. Repairing is a creative challenge.
    Making repairs is good for the imagination. Using new techniques, tools and materials ushers in possibility rather than dead ends.
  6. Repair survives fashion.
    Repair is not about styling or trends. There are no due-dates for repairable items.
  7. To repair is to discover.
    As you fix objects, you’ll learn amazing things about how they actually work. Or don’t work.
  8. Repair – even in good times!
    If you think this manifesto has to do with the recession, forget it. This isn’t about money, it’s about a mentality.
  9. Repaired things are unique.
    Even fakes become originals when you repair them.
  10. Repairing is about independence.
    Don’t be a slave to technology – be its master. If it’s broken, fix it and make it better. And if you’re a master, empower others.
  11. You can repair anything, even a plastic bag.
    But we’d recommend getting a bag that will last longer, and then repairing it if necessary.

Stop Recycling. Start Repairing. www.platform21.nl

Instead of buying the cheapest item, I think that we need to start thinking about the actual quality of the items we are purchasing. And we also need to start thinking about the total value of an item. This includes its aesthetic value. Objects should look good, feel good, be sturdy, and be capable of being repaired. If they worked well, we would actually use the item. If it looked good, we would likely take better care of it, and feel good about having it. If it was easy to repair, we would feel more investment in it.

Top