Thursday, May 9, 2024
 Popular · Latest · Hot · Upcoming
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 5102  / 1 Year ago, thu, april 20, 2023, 12:35:53

I am wanting to learn cron and I searched for some quality tutorials. I found How do I set up a cron job.



My goal is to have a folder on a network that will have sub-folders. Each sub-folder is a particular script that will be executed by the cron. I don't want to overload our system so how can I create the cron the run a shell script after the assigned time and previous script is ran?



Example:



Main Folder
Sub1 - script1
Sub2 - script2
Sub3 - script3

Cron 10:01 - runs script1
Cron 10:02 - runs script2
Cron 10:03 - runs script3
Cron 10:04 - runs script1
Cron 10:05 - runs script2

More From » 12.04

 Answers
2

Idea Outline



Your friend is an old fashioned cron companion at.




at and batch read commands from standard input or a specified file which are to be executed at a later time, using /bin/sh




Combine this with run-parts.




run-parts - run scripts or programs in a directory




The idea is that you write a cron job which starts the scripts in the "sub folders" with the use of run-parts.



If you want to parallelise the execution depending on the system load, you can wrap the execution of each single script with batch.



Example



On my installations I use my own wrapper script batchme. This provides some enhancements for mailing reports and output.



The cron.{daily,weekly,monthly} scripts are wrapped in my crontab this way:



@midnight   root  test -x /usr/sbin/anacron ||  for script in $( run-parts --list  /etc/cron.daily)  ; do batchme --quiet --info "cron-daily ${script}" ${script} ; done

@weekly root test -x /usr/sbin/anacron || for script in $( run-parts --list /etc/cron.weekly) ; do batchme --quiet --info "cron-weekly ${script}" ${script} ; done

@monthly root test -x /usr/sbin/anacron || for script in $( run-parts --list /etc/cron.monthly); do batchme --quiet --info "cron-monthly ${script}" ${script} ; done

[#32350] Friday, April 21, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
lasagnerhead

Total Points: 487
Total Questions: 105
Total Answers: 122

Location: French Southern and Antarctic Lands
Member since Sun, May 3, 2020
4 Years ago
;