cmdseq

Overview

cmdseq allows users to execute interleaved sequences of commands. Assuming the same counts and commands, on each execution cmdseq executes one of the commands, cycling through the sequence and wrapping back to the beginning when it is complete. For example, consider the following sequence:
$ cmdseq 2 "echo cmd1" 1 "echo cmd2"
cmd1
$ cmdseq 2 "echo cmd1" 1 "echo cmd2"
cmd1
$ cmdseq 2 "echo cmd1" 1 "echo cmd2"
cmd2
$ cmdseq 2 "echo cmd1" 1 "echo cmd2"
cmd1
cmdseq can be useful for integrating with tools such as cron. For example, if one is automatically synchronising large directories, one can set up a cron job which usually performs a quick synchronisation, occasionally performing a slow synchronisation:
$ crontab -l
*/9 * * * * cmdseq 200 "sync quick" 1 "sync full"
cmdseq works by storing a cookie file of its current position in any given command sequence. This cookie file is unique to each command sequence, and thus multiple command sequences can be safely used.

Download

You can also view cmdseq's git history. Patches are always gratefully received.

Usage

The command-line arguments are as follows:
cmdseq [-d <count dir>] <count1> <cmd1> [... <countn> <cmdn>]
Where:
-d <count dir> is a directory used to store command sequence cookies. It defaults to /tmp.
<count1> is an integer number of times cmd1 will be executed.
<cmd1> is a command to be executed. If the command has options, it should be surrounded by quote marks.
cmdseq exits with the exit code of whichever cmd it ran.