I have a hosting on hostgator and I just found out that they don't allow * * * * * cron jobs. If I have one that runs less than every 15 minutes, they change it to */17 or something like that. I searched but I can't find a way to do this on my own installations of cPanel. Any hints on how to replicate this.

Note: I'm not looking for an answer to by-pass this restriction. I'm trying to find out how to implement it on my own deployments.



I'm not aware of a standard package implementing this feature.

You can, of course, create a root cron job that checks and "fixes" user cronjobs. Take the following script for example - it's untested mostly, but it worked with the couple of examples I threw at it.

min=16 # the minimum allowed interval between runs
for crontab in /var/spool/cron/crontabs/*
  cp $crontab $crontab.bak
  # replace the * * * * * jobs with */16 * * * * jobs.
  sed -i "s/\* \* \* \* \*/\*\/16 * * * */" $crontab
  for i in `seq 1 $min`
    # replace */N * * * * for every N <= min
    sed -i "s/\*\/$i \* \* \* \*/*\/16 * * * */" $crontab

This assumes the crontab fields are separated by spaces, which may not be true - I used that assumption to keep the regex (hopefully) understandable. To make it more robust replace all spaces within the left-hand regexes with \s, if your sed supports it, or [ \t]+ (I think) if it doesn't.

Do note that the example applies 17 different search-and-replaces over each crontab, which of course will probably be unacceptable when the number of crontabs increases. To alleviate this issue you can use a single regex to match all possible infringing cronjobs. For example something like (untested): \*(/[0-9][0-5])* \* \* \* \* or a procedurally constructed one using the output of seq -s '|' 0 $min. Let me know if you need help with that.

  • Awesome. Thanks for the script. I'll wait a little while to see if someone else can point out a better solution (for example with a WHM addon). – recluze Jun 13 '11 at 3:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.