How to define every 5 hours in Crontab


 
Thread Tools Search this Thread
Operating Systems Solaris How to define every 5 hours in Crontab
# 1  
Old 10-28-2008
How to define every 5 hours in Crontab

Hi Experts,

I want to run a script which will move the files from particular directory to another backup directory After EVERY 5 hour.


How can I put it in crontab-

5 hours!!! * * * * /home/movefilescritp.sh

//purple
# 2  
Old 10-28-2008
Unix Crontab - setting up cron jobs using crontab

* 0,5,10,15,20 * * * /your/command (not tested!)

Last edited by DukeNuke2; 10-28-2008 at 12:33 PM..
# 3  
Old 10-28-2008
Hammer & Screwdriver Handling non-standard time delays in cron

Setup the cron to run every hour

At the beginning of the cron, have it do something like the following

Code:
time_ct=$(cat /tmp/cron_time_ct)
if [ $time_ct -lt 5 ]
   then
     echo "Not yet time"
     time_ct=$((time_ct+1))
     echo $time_ct > /tmp/cron_time_ct
     exit
   else
     time_ct=0
     echo $time_ct > /tmp/cron_time_ct
fi
# rest of your task

# 4  
Old 10-28-2008
joeyg, isn't it less troublesome to do it as a simple cronjob? why should we have these test cases?
# 5  
Old 10-28-2008
Hammer & Screwdriver Not sure if I have ever seen any other kind of solution

If I understand the request, the goal is to run at the following times (all in 24 hour time):

Sun 05:00
Sun 10:00
Sun 15:00
Sun 20:00
Mon 01:00
Mon 06:00
Mon 11:00
Mon 16:00
Mon 21:00
Tue 02:00
etc..

Thus, there is no regular pattern to supply to cron. And with 168 hours in a week, you cannot even play that since also not divisible by 5.
# 6  
Old 10-28-2008
Could execute the script (with full path name) once in background with "at now", and then use "at now + 5 hours" at the start of the script to spawn the script again. Needs a simple stop flag to stop the process.

#!/bin/ksh
COMMAND_LINE="$0"
if [ -f /tmp/stop_flag ]
then
exit
fi
echo "${COMMAND_LINE}" | at now + 5 hours
# Rest of the script
#


Note: The 5 hours may drift over a period of time due to cron and shell initialisation times.
# 7  
Old 10-28-2008
Quote:
Originally Posted by DukeNuke2
* 0,5,10,15.20 * * * /your/command (not tested!)
Won't that actually execute every minute for the hours you specified?
00:00
00:01
00:02
00:03
..
00:59
05:00
05:01
...
etc.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Define Variables

Hi, I just define the variable in script and use those script in another script but the variable not recognize. test1.sh #!/bin/bash DB="test_db" USR="test_user" PWD="test_pwd" HST="24.254.87.12" test2.sh #!/bin/bash ./test1.sh mysql -u $USR -p $PWD -h $HST... (2 Replies)
Discussion started by: fspalero
2 Replies

2. HP-UX

Crontab do not run on PM hours

Hi All I have a problem, I wonder if you can help me sort it out: I have the following entry in the cron: 00 1,13 * * * /home/report/opn_amt_gestores_credito.ksh > opn_amt_gestores_credito.log But the entry only runs at 01:07 I have stopped the cron deamon, and started, but it still... (39 Replies)
Discussion started by: fretagi
39 Replies

3. UNIX for Dummies Questions & Answers

Execute crontab for every 4 hours and begin from current time

I want to add a crontab entry which should execute for every 4 hours and that 4 hours calculation should begin from the current time. Normally if I set the crontab entry like this, 00 */4 30 05 * root date >>/tmp/cronout The above will execute the date command for every 4 hours like... (7 Replies)
Discussion started by: Ganeshwari
7 Replies

4. Programming

#define in c

Hi, I had a head file, looks like #define MIN_NUM 10 #define MAX_NUM 10 is there any way to get "MAX_NUM" from 10? thanks. peter (9 Replies)
Discussion started by: laopi
9 Replies

5. Programming

help with #define in C

if i do this in C #define NUM 1234512345 then how come i cant print it out using int main(int argc, char **argv) { printf("%d\n", NUM); return 0; } well the result is -1219236538, why isnt it 1234512345 ? (7 Replies)
Discussion started by: omega666
7 Replies

6. Programming

#define

Hello, I would like to conditionaly comment in my code source some fields from arrays. So I use the property ## from the #define definition. my code: ... #define slet /##* #define etsl *##/ ... const T_SVT_ADLL_A653_DESC A_DESC = { { slet qwerty etsl SLICING,... (3 Replies)
Discussion started by: cypleen
3 Replies

7. Shell Programming and Scripting

how to list files between last 6 hours to 3 hours

Hi Frens, I want to list some files from a directory, which contains "DONE" in their name, i am receiving files every minute. In this i want to list all the files which are newer than 6 hours but older than 3 hours, of current time i dont want my list to contain the latest files which are ... (4 Replies)
Discussion started by: Prat007
4 Replies

8. UNIX for Dummies Questions & Answers

#define in perl

Hi friends, I am not sure if perl questions can be raised here. :rolleyes: But I have a doubt if there is a way to do "#define" in perl, like in C. Does anyone know if it is feasible (without CPAN modules)? Thanks, Srini (7 Replies)
Discussion started by: srinivasan_85
7 Replies

9. UNIX for Dummies Questions & Answers

crontab every 2 minutes, 24 hours and once a week

can someone please check my answers for the crontabs I am making 1. how would I set up a crontab tab executes every 2 minutes each and every day of the week? answer: 2 * * * * /path/to/file.pl <-- is this correct? 2. how would I set up a crontab that executes every 24 hours at 2am?... (6 Replies)
Discussion started by: Bobafart
6 Replies
Login or Register to Ask a Question