LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 05-15-2010, 09:59 AM   #1
jsjones85
LQ Newbie
 
Registered: May 2010
Posts: 15

Rep: Reputation: 0
How do I run a script every 61 minutes?


Hi, I have a script I need to run hourly. I've looked around the net and found crontab.

The problem is, my script runs some macros I made using xmacro, which does some web surfing. So because of potential lag and whatnot, I want the script to run every 61 minutes rather than every 60 minutes. As far as I can tell, this is not possible in crontab.

Can someone please point me in the right direction?

Thank you very much.

Jeremy
 
Old 05-15-2010, 10:11 AM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
Similar question here:
http://www.linuxquestions.org/questi...terval-806495/

Also, search here at LQ using "crontab". There are quite a few threads.
 
Old 05-15-2010, 10:42 AM   #3
jsjones85
LQ Newbie
 
Registered: May 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Oops, I did do a search of "crontab" but it seems I didn't scroll down far enough. Thank you for the link.

Jeremy
 
Old 05-15-2010, 01:29 PM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,503

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
Hi Jeremy and welcome to LinuxQuestions!

To run a script every 61 minutes, you're forced to set a cron job that runs every minute. In fact, if the first run is at midnight, only after 61 days it will run at midnight again. In this 61-days interval it happens to run at all possible hour and minute pairs. Said that, the crontab entry must be
Code:
* * * * * /path/to/script.sh
Following the discussion in the thread linked by pixellany, inside the script you can try to set-up a check to see if the difference between the current date and a reference date of your choice is a multiple of 61 minutes. For example (using BASH)
Code:
#!/bin/bash
reftime=$(date -u -d "20100515" +%s)
timenow=$(date -u -d "$(date -u +"%Y%m%d %H:%M")" +%s)
if [ $(( ($timenow - $reftime) % 3660 )) -ne 0 ]
then
  exit
fi
<your code here>
In this example the main code will run every 61 minutes starting on 15-May-2010 00:00 UTC. Calculations are made in UTC to avoid weird results at the passage from/to Daylight Saving Time.

Last edited by colucix; 05-15-2010 at 01:36 PM.
 
Old 05-15-2010, 02:05 PM   #5
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
If the computer is running all the time there could be a single cron job to run at, say, midnight and it could use the at command to schedule itself to be run again in 61 minutes.
 
Old 05-15-2010, 02:54 PM   #6
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713Reputation: 713
Code:
while true
do
  # do stuff here every 61 minutes
  sleep 61m
done
The thing is that it won't really be run every 61 minutes, it will be run every 61 minutes + the time it takes to do what you wanted to do.
 
Old 05-16-2010, 07:20 AM   #7
jsjones85
LQ Newbie
 
Registered: May 2010
Posts: 15

Original Poster
Rep: Reputation: 0
Thank you everyone! Your replies have been very useful.
 
  


Reply

Tags
crontab, schedule, scripts


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
cronjob to run every 15 minutes? your_shadow03 Linux - Newbie 5 11-19-2009 10:58 PM
Setting up cron to proccess a Bash Script to run every 15 minutes jamtech Programming 3 07-30-2007 03:32 PM
Run a script every 10 minutes hraposo Ubuntu 3 11-08-2006 06:44 AM
howto run a script from cron every 5 minutes except 11pm-8am ? cccc Programming 2 03-20-2005 03:52 AM


All times are GMT -5. The time now is 09:49 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration