schedule is created to mimic linux’s “at” function which allows you to schedule a command/script/set of commands to run later.

schedule is a bash function (that you need to copy paste into your shell, or run from bash_profile/bashrc file)
since its function it will only last thru your shell and its subshells it will not interrupt other shells

I wrote a bash function called schedule, very basic style. Its like linuxes “at” command, which allows you to schedule a command for later. My version of FreeBSD is missing it (im using FreeBSD 8), im sure I Could install it somehow, but I just wrote a bash function to compensate.

BEFORE USING: edit these 2 items in the bash function.

  1. edit CRONTABFILE="/var/cron/tabs/root" to match the cron file that is accessed when you run crontab -e/crontab -l.
  2. edit /etc/rc.d/cron restart in the if statement towards the bottom (cron needs to be restarted so that it takes on your changes). Note that when you edit a crontab with crontab -e, it automatically reloads the crontab. I didnt find another way to reload the crontab other than restarting cron – shouldn’t be a big deal to restart cron.

The bash function (Tested with FreeBSD 8 and bash 4.x)

Copy paste that into your bash session and you will have that “schedule” function.

Just type “schedule” in bash to see how to use it:

To schedule something like “(date; df -h) >> /tmp/dfsize.txt” to run at the next 19:20pm (localtime to your box)

That will create a script in /tmp/crontab-EPOCHTIME-somerandomnumber.sh (that has +x executable bit so it can run). That script runs your  (date; df -h) >> /tmp/dfsize.txt and then it removes the job from cron.

After that script is created. It creates the following crontab line to your crontab

So then at 19:20 (7:20pm) this script runs /tmp/crontab-EPOCHTIME-somerandomnumber.sh which runs your command and then deletes that crontab line (thus ensuring it doesnt get deleted).

NOTE: it deletes it by grepping out /tmp/crontab-EPOCHTIME-somerandomnumber.sh (which should be unique thanks to EPOCHTIME and RANDOM)

The End.

Leave a Reply

Your email address will not be published. Required fields are marked *