checking for return status between multiple commands


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting checking for return status between multiple commands
# 1  
Old 11-19-2008
checking for return status between multiple commands

i have to run set of commands

command1
command2
command3
command4

Now Whenever any of these command fails i should quit while capturing error message.
Is there a better way then checking for $? after each command.
# 2  
Old 11-19-2008
checking for return status between multiple commands

function em {
echo "error [${1}]"
exit ${1}
}

command1 || em ${?}
command2 || em ${?}
command3 || em ${?}
command4 || em ${?}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Check status of long running multiple curl commands in shell script

I am working on script. it reads a file which contains multiple lines Ex; curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=1 curl --write-out %{http_code} --silent --output /dev/null http://hostname:port/input=2 curl --write-out %{http_code} --silent ... (2 Replies)
Discussion started by: oraclermanpt
2 Replies

2. Shell Programming and Scripting

Checking running process status using "grep" on multiple servers in load sharing system.

Suppose i have 3 different servers say x,y and z. Im running some process say ABC and 40 instances for the same is being created. In load sharing suppose on server x, 20 instances are running server y, 10 instances are running server z, 10 instances are running. While checking the... (1 Reply)
Discussion started by: ankitknit
1 Replies

3. Shell Programming and Scripting

Checking directory status

Can I use -ctime/-mtime to verify if a particular directory has been updated or not? I don't care about number of days. I just want to perform some operations only if the folder is modified (or it's metadata is modified), i.e. some files are added to the directory. This thread has a more... (1 Reply)
Discussion started by: Pramit
1 Replies

4. Shell Programming and Scripting

Return Status

Hi can you explain me, what does variables $@ and $* return and how are they used, if can give me a sample example it could be helpful. Thanks in advance, Regards, Abhishek S. (1 Reply)
Discussion started by: abhisheksunkari
1 Replies

5. Shell Programming and Scripting

checking the status of sendmail

Hi All, I like to check the status of sendmail and take the appropriate action based on success / failure etc. I have gone through one of the thread where a suggestion is made to use RC for return code Following is the code: ================================== #!/usr/bin/bash export... (0 Replies)
Discussion started by: tmanda
0 Replies

6. Shell Programming and Scripting

Checking the status of mail sent.

Hi, Is there any way to check the status of the mail sent or not.e.g mail -s "Error Message" abc@xyz.com <aaa/bbb/data.txt Can it return a status code which will confirm the delivery of mail sent?Please suggest. Thanks, Anil (1 Reply)
Discussion started by: anil029
1 Replies

7. Shell Programming and Scripting

Checking Status of PID

I'm developing a script that spawns many background processes that will be executing concurrently and need to check the exit status of each spawned process after it terminates. After starting the background process I can get the pid from $! which I can store in an associative array but how do I... (2 Replies)
Discussion started by: twk
2 Replies

8. UNIX for Dummies Questions & Answers

Checking return value of commands in pipe

Hi, I am wondering how I can check the return value of all commands in a pipe such as gzip -dc file.gz | sort -u > output.txt If I run this sequence in bash and check $?, I get the return status from sort. But I want to know if the initial gzip failed. Similarly for longer pipe chains,... (6 Replies)
Discussion started by: btherl
6 Replies

9. Shell Programming and Scripting

Checking Exit Status

I hope one of you smart people out there can help me with what seems like a real simple questing but I can't quite figure out. In a script I am doing a cmp on two files. I am trying to check the exit status with an if statement but can't seem to figure out the syntax. If the exit status is 1 I... (4 Replies)
Discussion started by: PrimeRibAndADew
4 Replies

10. Shell Programming and Scripting

Return status...

Hello there! Here is my problem. I hope I can get some help about it. I need to know how can I get the return code of an application in the Unix shell script. The script is like below: PREVIOUS STATEMENT & VARIABLES sqlplus scott/tiger @$sqldir/$sqlscript NEXT STATEMENT (Like... (7 Replies)
Discussion started by: Shaz
7 Replies
Login or Register to Ask a Question