Did my script execute successfully ?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Did my script execute successfully ?
# 1  
Old 04-22-2013
Hammer & Screwdriver Did my script execute successfully ?

Hi,

I have two scripts viz
Quote:
/tmp/commet/bin/connectdb1.sh &
and
Quote:
/tmp/commet/bin/connectdb2.sh &
I am running them in background.
I wish to know if both the scripts completed execution successfully.

So this is what I have done

Code:
/tmp/commet/bin/connectdb1.sh &
condb1=$?
/tmp/commet/bin/connectdb2.sh &
condb2=$?

However, I am getting error when trying to check.

Code:
if [$condb1 -ne 0] || [$condb2 -ne 0] ; then
echo " Error executing either of the two scripts ...."

[0: command not found

Is this the correct approach ? Why the error ?
# 2  
Old 04-22-2013
You should use code tags in your post. It makes it easy to read.
With more than 200 post I guess you should now the rules here.
# 3  
Old 04-22-2013
You didn't tell us your shell. I will assume ksh.

So how do you know your scripts have finished? You are simply getting the return code from the submission of a background job. I think you need something more like:-

Code:
(/tmp/commet/bin/connectdb1.sh;print $?>/tmp/db1.ret )&
(/tmp/commet/bin/connectdb2.sh;print $?>/tmp/db2.ret )&

wait

condb1=`cat /tmp/db1.ret`
condb2=`cat /tmp/db2.ret`

if [ $condb1 -ne 0 ] || [ $condb2 -ne 0 ]
then
   echo " Error executing one of the two scripts ...."
fi

Note the extra spaces in the if statement between the square brackets and the values. This might not apply in your shell, but it's a good bet it does looking at your message. Pretty basic stuff, but easy to get wrong.

This is a bit of a clunky way to do it, but this way will wait for both to complete before you get an answer. Is that okay? Be careful that there are no other background tasks, or it will wait for them too.

If you need to know as soon as one finished, there are ways to look at that, but hopefully the simple way will work for you.

Another way might be a co-process, but I'm not so good with them.




I hope that this helps,
Robin
Liverpool/Blackburn
UK
# 4  
Old 04-22-2013
Quote:
Originally Posted by rbatte1
You didn't tell us your shell. I will assume ksh.

So how do you know your scripts have finished? You are simply getting the return code from the submission of a background job. I think you need something more like:-

Code:
(/tmp/commet/bin/connectdb1.sh;print $?>/tmp/db1.ret )&
(/tmp/commet/bin/connectdb2.sh;print $?>/tmp/db2.ret )&

wait

condb1=`cat /tmp/db1.ret`
condb2=`cat /tmp/db2.ret`

if [ $condb1 -ne 0 ] || [ $condb2 -ne 0 ]
then
   echo " Error executing one of the two scripts ...."
fi

Note the extra spaces in the if statement between the square brackets and the values. This might not apply in your shell, but it's a good bet it does looking at your message. Pretty basic stuff, but easy to get wrong.

This is a bit of a clunky way to do it, but this way will wait for both to complete before you get an answer. Is that okay? Be careful that there are no other background tasks, or it will wait for them too.

If you need to know as soon as one finished, there are ways to look at that, but hopefully the simple way will work for you.

Another way might be a co-process, but I'm not so good with them.




I hope that this helps,
Robin
Liverpool/Blackburn
UK
It's BASH Shell. So, if you can help me code the above in BASH style. Can you explain the wait logic as I am not sure how long will it take to complete execution.

Last edited by mohtashims; 04-22-2013 at 02:13 PM..
# 5  
Old 04-22-2013
You might want to put the success or failure checks into your connectdb1.sh and connectdb2.sh scripts, referencing the specific script names in the output from each.

That way you'll get more specific info on each script's status.
# 6  
Old 04-22-2013
because I use shell i am getting this error

[: -ne: unary operator expected

Can someone give me the BASH equivalent of the below ?

(/tmp/commet/bin/connectdb1.sh;print $?>/tmp/db1.ret )& (/tmp/commet/bin/connectdb2.sh;print $?>/tmp/db2.ret )& wait condb1=`cat /tmp/db1.ret` condb2=`cat /tmp/db2.ret` if [ $condb1 -ne 0 ] || [ $condb2 -ne 0 ] then echo " Error executing one of the two scripts ...." fi
# 7  
Old 04-23-2013
Please use Code Tags
And do not quote complete post above you.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script replied multiple process for file has successfully created

Hi All, I have written the following code do FILE_NO=$(echo $LINE|awk -F"|" '{print $1}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') INST_NO=$(echo $LINE|awk -F"|" '{print $2}'|tr "'" '+'|sed 's/\(.*\)\(++\)\(.*\)\(++\)/\3/') if ] then ... (3 Replies)
Discussion started by: yogendra.barode
3 Replies

2. UNIX for Dummies Questions & Answers

Print script is completed successfully or not

Hai guys I am running three shellscripts through Gtk2-Perl(GUI) these are the scripts Drccalibrescript1 script2 script3 Gtk2-Perl(GUI) drccalibre -> If I run this script through Gtk2-Perl(GUI) these are results of the drccalibrescript1 . summary/.results I have to find size of... (1 Reply)
Discussion started by: kiran425
1 Replies

3. Programming

CGI Perl script to execute bash script- unable to create folder

Hi I have a bash script which takes parameters sh /tmp/gdg.sh -b BASE-NAME -n 1 -s /source/data -p /dest/data/archive -m ARC gdg.sh will scan the /source/data and will move the contents to /dest/data/archive after passing through some filters. Its working superb from bash I have... (0 Replies)
Discussion started by: rakeshkumar
0 Replies

4. UNIX for Dummies Questions & Answers

Cannot successfully execute .sh: su - <name> -c

Hi All, First time poster, I hope I have the basics covered. I am trying to execute a .sh but finding I am getting inconsistent results. A fresh set of eyes would be great. I am using Solaris 10 zones. So I am trying to execute a script but I am getting different results between... (2 Replies)
Discussion started by: att01
2 Replies

5. Shell Programming and Scripting

Script failing to run successfully on remote node

Hi guys, I have a scenario where i want to run a script from Node A. It ssh's into Node B and runs some awk commands there plus deposiriting the output on Node B. Challenge is that the awk commands run properly when executed locally on Node B but fail when within the script on Node B. I do not... (0 Replies)
Discussion started by: jerkesler
0 Replies

6. Shell Programming and Scripting

script has been executed successfully or not??

Guys, How can we know whether a script has been executed successfully or not ? We dont have any log directories, and we are not given a chance to modify the script. Could someone help me out with this Thanks (2 Replies)
Discussion started by: bobby1015
2 Replies

7. UNIX for Advanced & Expert Users

Script working successfully only when executed twice

Guys, i am facing a very strange issue, my code below does an ftp to server A and gets a file to Server B, once the file is in B an if condition is present to check if the pattern of the filename is ABC* then it has to be encrypted using OPENSSL as ABC.enc else if it of pattern 123* has to be... (3 Replies)
Discussion started by: meva
3 Replies

8. Shell Programming and Scripting

script execute or no execute

o hola.. Tengo un script que se ejecuta bajo una tarea del CronJOb del unix, tengo la version 11 de unix, mi script tiene un ciclo que lee unos archivos .txt luego cada uno de esos archivos debe pasar por un procedimiento almacenado el cual lo tengo almacenado en mi base de datos oracle 10g,... (4 Replies)
Discussion started by: Kespinoza97
4 Replies
Login or Register to Ask a Question