Crontab scheduler to execute script every 45 days


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Crontab scheduler to execute script every 45 days
# 1  
Old 09-05-2017
Crontab scheduler to execute script every 45 days

Can someone please help me on how to schedule script to run every 45 days in crontab ?

Thanks,
Prince
# 2  
Old 09-05-2017
It helps to have your OS like Ubuntu 16.1 or Solaris 10. It makes a big difference for date handling.

While you are giving that information:
Do you mean 45 days as:

1. the first of month 1, 15th of month 2, first of month 4.... restart every January 1

2. Today is the fifth. Add 45 dsays to that date, next time you run add 45 days. This means that every year the run shifts "backwards" by five days, and on leap year 6 days.

Calendars are not simple, we need to know exactly what your requirement for 45 days is.
# 3  
Old 09-05-2017
Sure, Am using red hat linux version 6. I have script for cleaning logs. I have to cleanup logs every 45 days. So i have to execute script every 45 days.

For example, If i run the script today then next script execution should be after 45 days.

Thanks,
Prince
# 4  
Old 09-05-2017
ever considered using at command?
The idea in your job execution, to do self execution by calling itself in 45 days using at...
I dp that sometimes...
This User Gave Thanks to vbe For This Post:
# 5  
Old 09-05-2017
try adding to cron:
Code:
00 00 * * * test $(( ($(date +\%s)/24/60/60) \% 45 )) = 0 && /path_to_script/clean_up_script

These 2 Users Gave Thanks to rdrtx1 For This Post:
# 6  
Old 09-06-2017
Have you investigated the logrotate command and configuration? That might save you having to craft your own. You can force a rotation based on several criteria as it suits your needs.



Robin
This User Gave Thanks to rbatte1 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Crontab does not execute script within a script

Hello All, I have a crontab schedule and its executing a script that is calling another script and does not execute. Crontab : ***** /test.sh and in test.sh /usr/local/file.sh and in file.sh webproxy -l 192.168.1.151 But when I run the script (test.sh) directly it works. But using... (1 Reply)
Discussion started by: Shaan_Shaan
1 Replies

2. Shell Programming and Scripting

Crontab job scheduler problem

Dear All. I have a scripts which does many task like house keeping, moving file to different location and loading the data into oracle. I run this scripts daliy manually , I decided to put it into cron. I have put the scripts into crantab but the behaviour of the scripts have changed. it... (2 Replies)
Discussion started by: guddu_12
2 Replies

3. Red Hat

root crontab wont execute a script

Greetings/ I have a script listed in my roots crontab 07 9 * * * /opt/HLRSDATA_2010_OCT/HLRS_Scheduler_sp.sh > /opt/HLRSDATA_2010_OCT/logs/HLRTKJob.log This script contains the following #!/bin/bash echo HLRSData Scheduler cd /opt/HLRSDATA_2010_OCT /usr/bin/java -Xms32m -Xmx1024m -cp... (6 Replies)
Discussion started by: RedSpyder
6 Replies

4. Red Hat

The crontab did not execute?

Dear! I've 2 scripts backup Oracle database in crontab environment, however, I found they did not execute. The cron is here $ crontab -l 30 2 * * 0 sh /cloudbck/level0/level0.sh 19 3 * * * sh /cloudbck/level1/level1.sh Then, I tried to find how did they not run by looking up... (8 Replies)
Discussion started by: trantuananh24hg
8 Replies

5. UNIX for Advanced & Expert Users

Crontab can not execute

Hi, on AIX 6.1, I put in crontab ,execution of myscript. But it sends back the following error : myscript.sh: rman: not found And in myscript I have : rman catalog rman/**@rep target / LOG=file.log << EOF run { allocate channel t1 type disk; ......... } exit EOF... (1 Reply)
Discussion started by: big123456
1 Replies

6. HP-UX

Run crontab every 6 days

Hi all, I need to run a shell script every 6 days using crontab. I've been searching a bit and found the following syntax for this: * * */6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>&1 respectively * * 0/6 * * /apps/temp/maxx.sh > /apps/temp/maxx.log 2>& Unfortunately when trying to... (8 Replies)
Discussion started by: Endo
8 Replies

7. UNIX for Dummies Questions & Answers

Crontab works but does not execute script

Hi guys, my first post time here, so hello to everyone :) I've got a problem running one of my scripts at work. I can get crontab working on simple scripts (i.e. one that just outputs date to a temp file). but it won't correctly execute the script i want to use. My script is a PHP script. It... (6 Replies)
Discussion started by: renegadeice
6 Replies

8. UNIX for Dummies Questions & Answers

how to execute sh script in bash shell via crontab

hello. we are porting over from HPUX Shell to Linux. my default shell is bash so i can no longer schedule to execute a sh script in crontab. can anyone pls help me out? I searched the site but didnt find any details. thanks! (1 Reply)
Discussion started by: jigarlakhani
1 Replies

9. Shell Programming and Scripting

Need to execute a complete url from crontab

Hi, I need to execute a URL through crontab. Please could you help me to. I need something like 15 0 * * * http://www.mysite.com/index.php. Is it possible. If not, how can I execute a script from another server.. Any help will be appritiatable. Many thanks, Nissar.P.K (2 Replies)
Discussion started by: nissar
2 Replies

10. Programming

crontab ..sqlplus cannot execute

i have shell script. when i run in normail mode..it run ok but when i use crontab command to set that program run in certain time it give an error. error 'SQLPLUS cannot execute' what the problem.i already set all the correct path and use both root and normal id but still cannot execute properly. (1 Reply)
Discussion started by: zikronz
1 Replies
Login or Register to Ask a Question