Running a cron every 7 minutes but to cary over the 7 minute count to the next hour?
Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I know that this has been asked before, but is there any way to have a cron job run every 7 minutes repeatedly? I suspect that one could write a script and that could be a good solution, but is that the simplest way? Can you avoid having to write a script (I'm not the strongest scripter)
I would run a script by cron every minute. The script counts up to 7 and then triggers the action and resets the counter. The counter is stored in a file. This could be as simple as appending a newline to the file every minute, and when the file size reaches 7 bytes, rm the file and execute the action.
I ran the following script by the command line, not by cron, and confirmed that it works. To run this via cron, I think you might like to place the counter file in an appropriate directory (for example, make it /var/local/timekeeper/count), and replace the second echo command with the desired command. If it is possible that the command will take longer than 1 minute, you must execute the command in a subshell. In my script, this is accomplished by ending the command line with an ampersand.
echo >> count_to_7
if [ "$(cat count_to_7 | wc -c)" -ge "7" ]
echo "We have 7." &
For extra credit, this method can easily be adapted to keep multiple counters with any number of different periods. For example, this script will independently trigger actions every 7, 11, and 13 minutes:
list_of_periods="7 11 13"
for period in $list_of_periods
echo >> count_to_$period
if [ "$(cat count_to_$period| wc -c)" -ge "$period" ]
echo "We have $period." &
Every 1001 minutes (since 7*11*13=1001), all 3 actions will be triggered at the same time.