invoke one script based on previous script execution

 
Thread Tools Search this Thread
Homework and Emergencies Emergency UNIX and Linux Support invoke one script based on previous script execution
# 1  
Old 08-26-2011
invoke one script based on previous script execution

I am database guy and not very good at shell scripts. I am seeking help to sharp my script coding. I have 5 scripts

1. master script. I use this one to call other four scripts to do database work.
2. db_backup_1 and log_backup_1
3. db_backup_2 and log_backup_2

in master script, I want to call db_backup_1 first. If this one run successfully, then server return 0, then invoke log_backup_1. If it failed, return 1, a email will be sent to me.

Then sleep 30 seconds

invoke db_backup_2, if it is succesul, return 0, invoke log_backup_2. If failed, return 1, another email will be sent to me.

My initial code like this. I know it must contains problems. I seek guru to help me to sharp this piece of code and make it work. Then I will do my test.

#!/bin/ksh

./db_backup_1.sh &
pid_db_backup_1=$!
wait $pid_db_backup_1
echo "db_backup_1 returned $?"
If ["$?" -eq "0" ]; then
./log_backup_1.sh &
else
mail -s 'db_backup_1 Unsuccessful' mymail@yahoo.com
fi

sleep 30

./db_backup_2.sh &
pid_db_backup_2=$!
wait $pid_db_backup_2
echo "db_backup_2 returned $?"
If ["$?" -eq "0" ]; then
./log_backup_2.sh &
else
mail -s 'db_backup_2 Unsuccessful' mymail@yahoo.com
fi

exit 0

thank you for your help in advance.

Last edited by duke0001; 08-26-2011 at 09:50 PM..
# 2  
Old 08-26-2011
Please post the script with CODE tags an proper indentation to make it easier to read.

there is no reason to put the job in the background the way it is written.

don't convert $? to a string. it works but for the wrong reasons

this will do the same thing. you want to exit on error.
Code:
./db_backup_1.sh
rc=$?

echo "db_backup_1 returned ${rc}"
if [[ ${rc} -eq 0 ]]
then
   ./log_backup_1.sh
   # check $? here??
else
   mail -s "db_backup_1 Unsuccessful rc=${rc}" mymail@yahoo.com </dev/null >/dev/null 2>/dev/null
   exit 1
fi

that should give you a few things to think about.
# 3  
Old 08-26-2011
frank:

Thanks for your advice. I think your code really works. I implemted code in master_script like this :

#!/bin/sh

echo "start to backup database"

./db_backup.sh
rc=$?

echo "db_backup.sh returned ${rc}"

if [[${rc} -eq 0 ]]
then

echo "database backup successful"

./log_backup.sh

else

mail -s " database backup Unsuccessful rc=${rc}" myemail@yahoo.com </dev/null

exit 1

fi

after db_backup-1 completed. testing exit failed. here is the error message. Please advice.

db_backup.sh returned 0
./master_script.sh[14]: [[0: not found.
database backup failed
mail: illegal option -- s
usage: mail [+] [-epqr] [-f file]
mail [-dt] persons

Last edited by duke0001; 08-27-2011 at 01:38 AM..
# 4  
Old 08-27-2011
Issue 1:
Put space between "[" and "$"; something like below:
Code:
 if [[ ${rc} -eq 0 ]]

Issue 2: Syntax for mail command is not correct.
This may vary depending upon type of OS. First try sending mail from command prompt, after that update proper syntax in script.

I hope this would help.
# 5  
Old 08-27-2011
psshah:

Thanks to point out the syntax errors in my coding. It works. I need to spend more time on shell scripting.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Depend on Script message needs to be invoke anothe script

I have script below #! /bin/bash if then echo "JBoss is NOT running" else echo "JBoss is running" fi If JBoss is NOT running need to be invoke another script i.e jboss startup script /home/vizion/Desktop/jboss-4.2.3.GA/bin/run.sh script from other script not... (5 Replies)
Discussion started by: Chenchireddy
5 Replies

2. Shell Programming and Scripting

Improve script made to calculate value based on present and previous line

Hi all, I have made at small script to make a simple calculation on a file which is formatted in this way: I want to create a new file in which the value of particular line minus the previous line is printed. So my wanted output is: I have made the following program to do the job... (5 Replies)
Discussion started by: s052866
5 Replies

3. UNIX for Advanced & Expert Users

Invoke unix script using c program

hi i want to invoke a unix script in a C program and also return some value from the script to the C program to use that value further. Basically i am doing a Lookup operation in this unix script and returning the looked up data from a oracle database table.. please help me invoke as well... (1 Reply)
Discussion started by: somi2yoga
1 Replies

4. Shell Programming and Scripting

Awk script to create new file based on previous line

Need help creating a script that does the following: Sort a file Compare the previous line "last field" with current line "last field" If they are the same, print output to a file If they are different print output to a new file The script should keep creating new files if the previous... (5 Replies)
Discussion started by: Muga801
5 Replies

5. Shell Programming and Scripting

Automatically Rerun a script based on previous execution output

Hi Experts, I have a shell script called "updatevs" that is scheduled to run at 6.00 am everyday via cronjob. The cronjob will execute this script and output to a log file. The functionality of this script is to read the database and run a set of commands. This script is generally successful... (6 Replies)
Discussion started by: forumthreads
6 Replies

6. Shell Programming and Scripting

Not able to invoke a sh script from KSH

Hi all, Iam writing a KSH script which needs to export dispaly to Xwindows and then involke a sh script .. But a core file is getting genrated for reasons not known to me. Please check i need incorporate below mentioend code in my script which iam not abel to .. export DISPLAY=`who am i |... (1 Reply)
Discussion started by: rahman_riyaz
1 Replies

7. Shell Programming and Scripting

Invoke shell script in cgi script

Hi, I just tried to call a simple shell script from a cgi script writing in c programming.But,it is not working.i will be grateful if anyone can show me the problems going on as i m new to c and oso shell script.Thanks. -Here is my shell script of call the 'pc shut down' system command in... (1 Reply)
Discussion started by: carolline
1 Replies

8. Shell Programming and Scripting

Invoke script depending on previous scripts

Hi, I am in desperate needs for advice! I have a script which would invoke various java programs depending on the input parameter and a script which would perform calculation on the data inputted by the first script. The schedule of the job is like this 1) 10:00 am to 11:00 am: call java... (0 Replies)
Discussion started by: mpang_
0 Replies

9. Shell Programming and Scripting

invoke same script twice

hey, can I invoke the same script twice simultaneously? I want both instances to run at the same time with different parameters. Thanks! (2 Replies)
Discussion started by: mpang_
2 Replies

10. Shell Programming and Scripting

how to invoke shell script

hi everybody, i learning unix now only.Can u pls guide me in invoking a shell script.Actually i need to know how to write the command for invoking the shell script.Suppose the shell file name is count , then how i will write the command. thanks (1 Reply)
Discussion started by: gopa_mani
1 Replies
Login or Register to Ask a Question