Current versions of cron support sophisticated syntax making creating weird schedules a breeze. With older versions of cron you normally had to schedule multiple jobs to fill every time slot in a complex schedule. The most common of uncommon requirements is to run a cron job every so many minutes.

To run a cron job, say, every 55 minutes, these days you can just schedule “ */55 * * * * ” you’ll be good to go. On older Unix systems you’ll encounter an error, such as “unexpected character found in line” in Solaris 10. The solution is to create a wrapper script and rely on epoch time to calculate time intervals.

Here’s a simple example: let’s say every 55 minutes you need to “ date >> /var/adm/messages “. First, you create the wrapper script (say, /var/adm/bin/date_cron_wrapper.sh):

The weirdness you see with “truss” and “nawk” is due to lack of epoch option for the “date” command on Solaris 10. On systems that do support “ date +’%s’ “, you can simply do this:

Now you can schedule the cron job:

The script will run a modulo operation on the current epoch time to see if the remainder after dividing by 3300 seconds (55 minutes) is zero. If that’s the case, then 55 minutes have passed and the wrapper script will execute its payload. You can get away with running this cron job every five minutes, instead of every minute.

 

Leave A Reply

Please enter your comment!
Please enter your name here