Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Job scheduling in Unix

Posted on 2015-01-05
9
Medium Priority
?
127 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Nothing ever in the clear!

This technical paper will help you implement VMware’s VM encryption as well as implement Veeam encryption which together will achieve the nothing ever in the clear goal. If a bad guy steals VMs, backups or traffic they get nothing.

 
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

Application Discovery Service in AWS

In the era of the cloud, customers migrating away from their existing on-premise infrastructure. This requires lots of planning, strategies, and effort to identify their existing resources and determine how best to migrate.  Datacenter migrations happen in four phases -

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Utilizing an array to gracefully append to a list of EmailAddresses
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…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

688 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