ssnoor
asked on
Cronjob Setting for three scenario
I have a Linux shell script . I need to run cronjob so that script can run every 7 days.
I have another scripts run every hour in batch process
Final script should be run every 25 minute in batch . Please let me know all setup in cronjob for three scenarios.
Thanks
Shaiukh
I have another scripts run every hour in batch process
Final script should be run every 25 minute in batch . Please let me know all setup in cronjob for three scenarios.
Thanks
Shaiukh
ASKER
Hello
I did not understand weekly and hourly . I need to run in batch process . How can I setup cronjob for weekly and hourly in batch process.
Thanks for correcting me for 30 minute setup.
I did not understand weekly and hourly . I need to run in batch process . How can I setup cronjob for weekly and hourly in batch process.
Thanks for correcting me for 30 minute setup.
Use the command...
Then type in the above entries into your crontab file... literally... byte for byte...
https://crontab.guru/ gives a quick run through.
All modern CRONs... say released over the last 5-10 years support all the "@" prefixed shortcuts.
crontab -e
Then type in the above entries into your crontab file... literally... byte for byte...
https://crontab.guru/ gives a quick run through.
All modern CRONs... say released over the last 5-10 years support all the "@" prefixed shortcuts.
Like david mentioned: @weekly... which is short for:
(man 5 crontba will tell you btw)
Instead of the first five fields, one of eight special strings may appear:
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
(man 5 crontba will tell you btw)
Instead of the first five fields, one of eight special strings may appear:
string meaning
------ -------
@reboot Run once, at startup.
@yearly Run once a year, "0 0 1 1 *".
@annually (same as @yearly)
@monthly Run once a month, "0 0 1 * *".
@weekly Run once a week, "0 0 * * 0".
@daily Run once a day, "0 0 * * *".
@midnight (same as @daily)
@hourly Run once an hour, "0 * * * *".
Are the three scripts related?
What is the relationship between the run every 25 minutes, an hour and 7 days
If you can combine all three into a single script with three functions.
Run the script every five minutes.
The 25 minute use touch to mark last run.
In the every 25 minutes, compare whether age of file, is more than 25 minutes at which point it will fire the process.
Repeat the same on the hourly, and every 7 days.
What is the relationship between the run every 25 minutes, an hour and 7 days
If you can combine all three into a single script with three functions.
Run the script every five minutes.
The 25 minute use touch to mark last run.
In the every 25 minutes, compare whether age of file, is more than 25 minutes at which point it will fire the process.
Repeat the same on the hourly, and every 7 days.
* * * * 1 /home/runs_on_mondays
# if you want Tuesdays - change 1 to 2
0 * * * * /home/runs_every_hour
# runs at every whole hour -if you want at 1:10, 2:10 - change 0 to 10
*/5 * * * * [ $(( $(date +%s) / 60 % 25 )) -eq 0 ] && /home/runs_every_25mins
# this is a PFE one - modulo 25 - change to 35 if you like or when every 15 minutes just do this:
*/15 * * * * /home/runs_every_quarter
# if you want Tuesdays - change 1 to 2
0 * * * * /home/runs_every_hour
# runs at every whole hour -if you want at 1:10, 2:10 - change 0 to 10
*/5 * * * * [ $(( $(date +%s) / 60 % 25 )) -eq 0 ] && /home/runs_every_25mins
# this is a PFE one - modulo 25 - change to 35 if you like or when every 15 minutes just do this:
*/15 * * * * /home/runs_every_quarter
This question needs an answer!
Become an EE member today
7 DAY FREE TRIALMembers can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Open in new window
To run a CRON job every 25 minutes (oddball number), you'll have to write a series of CRON entries which vary the hour + minute to come up with exactly 25 minute increments.
Likely best to stick with once every 30 minutes to keep your CRON job self documenting.