I waited a few days to let others give a try at this. Here are some possibilities:
- Use batch which comes along with at. If atd is not running, ask your sysadmin about this. I've access to the Linux version which might be completely different than the AIX version.
With batch you give it the commands from standard input. It queues the commands to run (by atd) when the system load average is below a threshold (specified by atrun or atd).
Cons: Your jobs might not affect load, so this might be useless. A job might suddenly become IO bound, fooling atd to run the next program.
-
SGE - Sun Grid Engine. It's a full-featured batch submission engine, but it might be overly complex for this kind of application. On the other hand, it's relatively easy to set up.
-
Custom queue:
Instead of the command actually doing the work, override it with a shell function that outputs the command and parameters to a FIFO. Here's the gist of this:
umask 077
mkdir -p $HOME/var/run
mkfifo $HOME/var/jobq
Now create a cronjob (to run every minute) to read the queue and execute the next command, as long as the previous is not still running:
* * * * * $HOME/bin/batch_execute.sh
in $HOME/bin, you can create the script:
#!/bin/sh
# If another job is running, exit immediately
test -f $HOME/var/run/jobq.lock && exit 0
# lock the queue (exit with 256 on failure)
touch $HOME/var/run/jobq.lock || exit 256
# read the queue
read job < $HOME/var/run/jobq
# run the program
eval $job
# remember job's exit status
status=$?
# remove the lock when done
rm -f $HOME/var/run/jobq.lock || exit 257
# exit with job's exit status
exit $status
There is a big problem with this scheme, however: the writers will block until the reader is available. So the job submitter must go into the background until the reader is available. Here's such a job-submitter.
#!/bin/sh
# submit.sh
echo $* > $HOME/var/run/jobq &
Prefix all your jobs with this "submit" script (which should be in your PATH or hard-coded as something like $HOME/bin/submit.sh).
I haven't tested this, and there maybe some problems. But give it a try.