Simple queuing system?

There's a standard batch command that does more or less what you're after. More precisely, batch executes the jobs when the system load is not too high, one at a time (so it doesn't do any parallelization). The batch command is part of the at package.

echo 'command1 --foo=bar' | batch      
echo 'command2 "$(wibble)"' | batch
at -q b -l              # on many OSes, a slightly shorter synonym is: atq -q b
at -q b -r 1234         # Unschedule a pending task (atq gives the task ID)

Another solution is to use lpd, and create a custom "print driver" that runs your jobs. A friend helped me work this out when I had a similar request. Make a script like this, and put it in /tmp/batch.sh:

#!/bin/bash

TMPFILE=$(mktemp /tmp/XXXX)
exec <"$6"
cat - > $TMPFILE
chmod a+x $TMPFILE
$TMPFILE
rm -f $TMPFILE

Then run:

lpadmin -p batch1 -E -P /tmp/batch.sh

That starts a queue, and you can create more by using other names instead of batch1. Add a job with:

lp -d batch1 /path/to/jobscript

Manage jobs with lpq, lprm, and lpstat. If you want more flexibility with passing arguments to your jobs, you can make the batch.sh script fancier.

(I tried batch before going down this route, but either it doesn't work as a queue on OSX, or I was using it wrong.)


There are lots of queuing systems, but the are frequently very specialized.

You might look into the at scheduler. It's like cron in some ways but it is setup more like a queue for one time jobs than for repeat jobs. It can "schedule" things on criteria other than time, such as system load or sequence of jobs.

Your favorite distro will almost certainly have packages for it.