CRON – multiple cron jobs on one line (running consecutively, not concurrently)

This post will (hopefully) remind me in the future how to do something very simple.

A crontab is normally running one command on each line. EG:

# m h dom mon dow command
01 00 * * * /home/cronscripts/vine-warn-when-large-user-profile
05 00 * * * /home/cronscripts/
01 01 * * * /home/cronscripts/vine-samba-users
01 02 * * * /home/cronscripts/vine-database-backups

So the above jobs run at 00:01, then 00:05, then 01:01am then 02:01am.

Instead, I can run these cron tasks one after the other by putting && between each task. EG:

# m h dom mon dow command
01 00 * * * /home/cronscripts/vine-warn-when-large-user-profile && /home/cronscripts/ && /home/cronscripts/vine-samba-users && /home/cronscripts/vine-database-backups

So these jobs start running at 00:01am. When vine-warn-when-large-user-profile finishes, starts immediately, and so on.

Why is this useful?

I have several backup scripts for our linux servers. Each script creates a tar archive of a directory, compresses it, SFTP’s it off site, then deletes the tar archive from the server.

If the scrips all run at the same time, the server runs out of disk space. I need them to run one after the other. I can’t effectively guess when to start each one. The backup can’t start until after midnight and must be finished by 7am when users are likely to start work again. Some directories can take minutes to archive, compress, send, delete. Others can take 2 or 3 hours. One server also collects backups from a couple of other places, so that script has to complete before others start too.

Running this scripts concurrently means no useful transfer time is lost and I don’t have to guess the time each script will take to run.

Search this site

Free apps

  • – Your birthday or other celebration date based on [years on other planets] / [how many seconds/days] / [how far you’ve travelled around the sun]
  • – Calculates the combination and how many 1st, 2nd, large 1st and large 2nd class Royal Mail stamps you need on large envelopes and packets

Recent posts