Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Job scheduling in Unix

Posted on 2015-01-05
9
Medium Priority
?
129 Views
Last Modified: 2015-01-19
Hi,

I have 10 shell scripts which need to be run in a sequence manner. In my early works i used Autosys but now we cant afford it .

Is there any free schedulers available so i can configure it ? Ie. script1.sh is parent and script2.sh will execute only after script1.sh completed and script3.sh will execute only after completion of script1.sh and script2.sh etc.

Please advice.

Thanks,
magento
0
Comment
Question by:magento
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 600 total points
ID: 40532908
you can use crontab to schedule jobs on unix / linux systems.

For more info on using crontab, please see:

http://code.tutsplus.com/tutorials/scheduling-tasks-with-cron-jobs--net-8800

Also, you can have one master shell script scheduled with crontab to run at specific times, and that master script will run your scripts in sequence, e.g. master script could be like below:

/path/to/script1.sh
/path/to/script2.sh
/path/to/script3.sh
/path/to/script4.sh
/path/to/script5.sh
/path/to/script6.sh
/path/to/script7.sh
/path/to/script8.sh
/path/to/script9.sh
/path/to/script10.sh

The above will run the scripts in sequence and the start of next script will be after the completion of the previous one.

Please note while scheduling you need to take care of overlapping between crontab jobs. e.g. if running the scripts takes more than an hour, then you need to run the job every 1 hour, then you need to take care of the overlap of jobs
0
 
LVL 5

Author Comment

by:magento
ID: 40532924
I will check the timing, but in worst case if it takes more time , Is it a good idea i can use lock for the master script and so the cron wont start until the lock of PID for master script completed?
0
 
LVL 5

Author Comment

by:magento
ID: 40533051
Also what is script5.sh was failed ? so i think this not going to help my situation?
0
Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

 
LVL 40

Expert Comment

by:omarfarid
ID: 40533083
At the beginning of master script you can check if there is a lock and accordingly proceed.

At the end of the master script you need to remove the lock. Be careful here where the lock will be there if the master script exit before removing the lock.

For the case  where a script is failing in between, you can check the the exit status of the previous script by checking the value of $? , if it is 0 (zero) then the scrip exit successfully other value means error, and accordingly proceed with other scripts run.
0
 
LVL 21

Expert Comment

by:tfewster
ID: 40534225
Regarding Free scheduling software, a web search for "linux job scheduling software freeware" shows many possibilities, and even a Wikipedia comparison of the better known ones.  If your scheduling is more complex than "run scripts in sequence on a single server (and halt if one fails)" and if you're familiar with AutoSys you'll know what functionality you need.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 40534478
Do you want the any of the scripts to run in parallel?

What behaviour do you want if any of the scripts fail?

How long will they usually take to run?

How often do you want to schedule them?
0
 
LVL 5

Author Comment

by:magento
ID: 40534563
Hi Tintin,

Do you want the any of the scripts to run in parallel?
>>I want them to run in an sequence manner.
What behaviour do you want if any of the scripts fail?
>>If script4.sh failed, then it should be stopped right there.
How long will they usually take to run?
>>This will finish within 20 mins
How often do you want to schedule them?
>>Every minute.
0
 
LVL 48

Accepted Solution

by:
Tintin earned 1400 total points
ID: 40534616
Schedule a master script in cron, that has:

#!/bin/bash
# Exit if another copy of this script is running
pidof -s -o '%PPID' $(basename $0) >/dev/null 2>&1 && exit 1

function run {
  eval $*

  if [ $? -ne 0 ]
  then
        echo "$* failed"
        exit 2
  fi
}

for i in {1..10}
do
   run /path/to/script$i
done

Open in new window

0
 
LVL 40

Expert Comment

by:omarfarid
ID: 40534839
If running the scripts takes 20 min, how do you expect to schedule to run every min? There will be overlap
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways ca…
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Suggested Courses
Course of the Month9 days, 12 hours left to enroll

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question