Staus of Executed Scripts


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Staus of Executed Scripts
# 1  
Old 05-11-2005
Staus of Executed Scripts

Hi There,

I have 3 scripts that have to be run one after the other. All 3 scripts are dependent of the other. Now, If I am about to run the second script, assuming that the first script has already been run, can I get the status of the first script.

The problem is that, My second script has to run only when my first script has excuted successfully

If this can be done, give me a snippet of doing this

Thanx in advance
# 2  
Old 05-11-2005
In the good ol' /bin/sh shell, $? holds the status of the just executed script.

In unix, 0 denotes a success.

Suppose your scripts are a.sh, b.sh and c.sh and you need to run them in the order a, b, c; then this is what you should be doing.

Code:
#! /bin/sh
sh a.sh
if [ $? -eq 0 ] ; then
 sh b.sh
  if [ $? -eq 0 ] ; then
   sh c.sh
  else
   echo "b failed"
   exit
  fi;
  else
 echo "a failed"
  exit
fi;

Havent tested it yet. Let me know if you hit any roadblocks.

Vino
# 3  
Old 05-11-2005
Status of shell scripts

Thanx,
It is ok if u I am executing the scripts within the script. What if I run the scripts independently and not within a single script

sh a.sh

sh b.sh

sh c.sh

What is the possible way getting the exit status of a.sh before executing b.sh?

Thanx in advance
# 4  
Old 05-11-2005
Let me get this clear.

You want the scripts to run independently or are they dependent on the other scripts ?

If they are dependent, then i think you need to have a script which outsources the scripts separately. In this case, you run the main script and then go about your work. It will continue on its own.

If they are independent, then I think you come into the picture. You can see for your self whether a is successful or not and then go ahead likewise for b and c.

Also, $? holds the exit status of executed command be it any command

vino
# 5  
Old 05-11-2005
pathanjalireddy,

Another thought !

If you dont want to one script handling all three scripts, then in each of your scripts you will have to test for the exit status.

Say in a.sh you have commands which can throw a non-0 exit status. For each of these commands you will/might (as per your requirements) have to check the exit status given by $?. And then accordingly, proceed ahead.

Vino
# 6  
Old 05-12-2005
use temp marker files ... at the end of your script create the marker file ... look for the marker file at the start of the next script ...
Code:
a.sh
...
...
touch /tmp/a.complete

b.sh
#! /bin/ksh
[ ! -f /tmp/a.complete ] && exit
...
...
touch /tmp/b.complete

c.sh
#! /bin/ksh
[ ! -f /tmp/b.complete ] && exit
...
...
touch /tmp/c.complete

# 7  
Old 05-12-2005
Just Ice,

What happens, the next time you run a.sh and it fails.

/tmp/a.complete would still remain there. And b.sh would run.

Rather, once you enter b.sh and check for the existence of /tmp/a.complete, you should remove the file before carrying on with b.sh.

Vino
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

When were all scripts on the Solaris server last executed?

Hi All, I am new to this forum and I am hoping someone will be able to help me:) I have inherited a very old Solaris server that has a number of scripts around 500 in total. I need to migrate the scripts to Linux but I would like to know which ones are currently being executed rather... (10 Replies)
Discussion started by: josamy
10 Replies

2. Shell Programming and Scripting

Need to Replace the the Staus in last line

Hi Team, I have a increamental file like : 1033|20160120211644126508|1845828861|IN PROGRESS| 1033|20160120220756541604|1845828861|IN PROGRESS| 1033|20160120221051036757|1845828861|IN PROGRESS| 1033|20160120221208839263|1845828861|IN PROGRESS| 1033|20160120222550394230|1845828861|IN... (1 Reply)
Discussion started by: D_Sethi
1 Replies

3. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (6 Replies)
Discussion started by: Madhu Siddula
6 Replies

4. Shell Programming and Scripting

Multiple shell scripts executed in one script

Hi every one, i am new to shell script. my people given a task to write a shell script that should execute number of shell scripts in that. in that, if any shell script is failed to execute, we have to run the main script again, but the script should start execute from the failed script only.. it... (1 Reply)
Discussion started by: Madhu Siddula
1 Replies

5. UNIX for Advanced & Expert Users

Procedure to be executed from shell scripts

Hi, I am looking for a script wherein i will be able to execute below procedures one by one in line and next procedures starts only when the previous one completes and also after execution of each procedure i will be getting a automted mail as "PL/SQL PROCEDURE SUCCESSFULLY EXCETUTED". ... (1 Reply)
Discussion started by: sv0081493
1 Replies

6. AIX

Script not getting executed via cron but executes when executed manually.

Hi Script not getting executed via cron but executes successfully when executed manually. Please assist cbspsap01(appuser) /app/scripts > cat restart.sh #!/bin/ksh cd /app/bin date >>logfile.out echo "Restart has been started....." >>logfile.out date >>logfile.out initfnsw -y restart... (3 Replies)
Discussion started by: samsungsamsung
3 Replies

7. Shell Programming and Scripting

KSH - How to call different scripts from master scripts based on a column in an Oracle table

Dear Members, I have a table REQUESTS in Oracle which has an attribute REQUEST_ACTION. The entries in REQUEST_ACTION are like, ME, MD, ND, NE etc. I would like to create a script which will will call other scripts based on the request action. Can we directly read from the REQUEST_ACTION... (2 Replies)
Discussion started by: Yoodit
2 Replies

8. Shell Programming and Scripting

Server Staus offline to online -Shell script

Hi, We put cron entry :whenever server is offline(checks every 5 minutes) it sends status to mailer group. The number of messages (offline)were growing in our mailbox.How to avoid not to send offline messages after the first one through shell script. Thanks in advance. Chowdary (2 Replies)
Discussion started by: chowdary_m
2 Replies

9. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

10. UNIX for Advanced & Expert Users

script to Monitor raid staus --Sun Volume manager

We use Sun Volume manager to mirror root disks and other local disks... Is there any script to monitor raid status across all machines send output thru email? Help is appreciated. Thanks. (1 Reply)
Discussion started by: sriny
1 Replies
Login or Register to Ask a Question