Need cron job that runs every 182 minutes

1

Currently running Linux Mint 18.1; closest I can get to the desired result is an ugly kludge where I set cron to 0 */4 * * * ck-cp with the script named "ck-cp" containing a sleep command for 90 seconds prior to executing the command that does the actual checking. Due to the nature of the job, it works about 85% of the time, failing the other 15%.

In Windows, oddly enough, it is easily accomplished. You simply tell Task Scheduler to run the job every 182 minutes. Works 100% of the time.

I find this difference in behavior curious, especially since *nix is far, far older than Windows, and generally more reliable. Anyone have any insight into how to get cron to do this? (And the above is the best I've found so far...)

Raymond Danner

Posted 2016-12-28T19:26:45.867

Reputation: 57

Answers

5

You can do it by scheduling your script to run every minute using cron and then bailing out when the time since epoch doesn't mod to 0.

#!/bin/bash

minutesSinceEpoch=$(($(date +'%s / 60')))

if [[ $(($minutesSinceEpoch % 182)) -ne 0 ]]; then
    exit 0
fi

# ... your stuff here...

Allain Lalonde

Posted 2016-12-28T19:26:45.867

Reputation: 278