LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2011, 07:06 AM   #1
sandy_linux
LQ Newbie
 
Registered: Aug 2005
Posts: 13

Rep: Reputation: 0
set cron to run job every 30hours


I was wondering how to set the cron to run every x hours, where x is greater than 23 ? I have a script that runs for 28hours and hence I want to schedule this every 28hours. How can I do it?

Thanks
 
Old 09-02-2011, 07:48 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Please, take a look at this: http://www.linuxquestions.org/questi...7/#post3772149.
 
Old 09-02-2011, 08:21 AM   #3
sandy_linux
LQ Newbie
 
Registered: Aug 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Thanks for pointing me to this thread. But, I wonder about the statement:

"at now +4 days" means "at now +30 hours". really? What will I then write when I want to execute the script after 4 days? I guess, same?
 
Old 09-02-2011, 08:25 AM   #4
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
You could do it without cron.
Modify your main script so that the last thing it does is call the at command.
i.e. if your script is called main.sh ...

Code:
at now + 1 minute < ./main.sh
Of course you will have to make sure that any log files that your script creates will be moved or renamed before the script is repeated.

Here is a sample script, just check on main.txt to see what happens. Comment out the at command to stop the script repeating.

Code:
#!/bin/bash
############
## main.sh #
############

echo `date` >> main.txt
for a in `seq 10`
do
echo "hello $a" >> main.txt
done
echo "---------------------" >> main.txt
at now + 1 minute < ./main.sh
 
Old 09-02-2011, 08:32 AM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976Reputation: 1976
Quote:
Originally Posted by sandy_linux View Post
Thanks for pointing me to this thread. But, I wonder about the statement:

"at now +4 days" means "at now +30 hours". really? What will I then write when I want to execute the script after 4 days? I guess, same?
Well.. that was not the post at which I've redirected you. Anyway, yes... you can use at instead of cron as pointed out by smoker above.
 
Old 09-02-2011, 09:38 AM   #6
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,326

Rep: Reputation: 253Reputation: 253Reputation: 253
There is also gnubatch, which is not a full blown resource manager (aka queuing system) but meant as a replacement for cron:
Code:
$ gbch-r -A - -r hours:30 foobar.sh
$ gbch-jlist -H -F "%N %U %H %I %p %L %T %c %P %r"
Jobno User  Title     Cmd Interp Pri Loadlev Date/time        Cond Progress Repeat
31849 reuti foobar.sh sh         150    1000 02/09/2011 15:30               Hours:30
$
$ gbch-jlist -H -F "%N %U %H %I %p %L %T %c %P %r"
Jobno User  Title     Cmd Interp Pri Loadlev Date/time        Cond Progress Repeat
31849 reuti foobar.sh sh         150    1000 03/09/2011 21:30               Hours:30
will repeat the job every 30 hours from now (unless you give a different time for the first start). I added -A - as the default is to skip the weekend.

Depending on the return code of the job you can increase/decrease variables inside gnubatch to start/stop other jobs at certain conditions. You can also shift the next execution if necessary or limit it to 15 runs or so.
 
  


Reply


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
Run cron job in every 20 second ust Linux - Newbie 13 01-15-2015 02:01 PM
How would I set a cron job to run every 7 minutes between 7pm and 11pm? ghurty Linux - Server 4 12-13-2010 05:06 PM
How to set up a Cron Job to run every other week or every three months etc. kckabobus Linux - Newbie 3 04-03-2008 02:36 PM
How do I set my profile in CRON job? lolson33 Linux - General 2 12-06-2005 05:18 PM
how to set cron job to run every 5 mins? gsbarry Linux - General 7 05-28-2003 01:30 PM


All times are GMT -5. The time now is 12:29 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration