Find the answer to your Linux question:
Results 1 to 2 of 2
I do have a large number of cronjobs that I want to consolidate. The cronjobs are all calling the same script, but with a job specific tag. The jobs execute ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2007
    Posts
    1

    cronjob - shell script related problem


    I do have a large number of cronjobs that I want to consolidate. The cronjobs are all calling the same script, but with a job specific tag. The jobs execute an application backup job using a different configuration file. I have a total of 20 jobs and 20 different (pre-configured) configuration files. The jobs get executed in a 6 hour period one after another. Each job is a required pre-requisite for the next job to be successfully executed.

    Somebody suggested that I should dump the commands into a shell script and then run a single cronjob against the shell script. Now I do not know how the shell script execution 'behaves' in regards to execution. Let's say I list my 20 crons one after another. How is that being executed? Does the script executes line 1 first and waits for the success message and then moves to line 2 and so on? Or what better way can I use to run my cronjobs? Here is an example of my jobs:

    25 18 * * 5 /usr/local/v-backup/v-backup.pl -c /usr/local/v-backup/app-1-backup.cfg > /var/log/vbackup/app-1-backup.log
    55 18 * * 5 /usr/local/v-backup/v-backup.pl -c /usr/local/v-backup/app-2-backup.cfg > /var/log/vbackup/app-2-backup.log
    25 19 * * 5 /usr/local/v-backup/v-backup.pl -c /usr/local/v-backup/app-3-backup.cfg > /var/log/vbackup/app-3-backup.log
    and so on ....
    Any ideas?

    Thanks.

    Chris

  2. #2
    Linux Engineer
    Join Date
    Nov 2004
    Location
    home
    Posts
    796
    Shell scripts can run commands either. Just the command, like so:
    Code:
    /usr/bin/something
    will wait for the command to finish before moving on. Putting an & after it:
    Code:
    /usr/bin/something &
    spawns it in the background and moves on without waiting. Also, you can have a command run only if the previous commands run by using && :
    Code:
    /usr/bin/something --run-first &&
    /usr/bin/something --run-second &&
    /usr/bin/something --run-third
    This way the third one won't execute unless the first two both exited successfully. The fancy way is to use some if statements to find the return value and if one command doesn't finish, it will tell you where it stopped. Look into bash scripting and there's a bit more you can do.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •