Linux.com

Author Message
Joined: Dec 20, 2008
Posts: 34
Other Topics
Posted Dec 22, 2008 at 3:36:54 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
Hello, I need help regarding this issue. I have executed one programe which validate some file. When I run another programe I want to use the exit status of the last programe. Because I have to take some decision one the basis of it exit status of last program. I dont know how can I achieved this. If you have some idea please give me. I would be very thankful to you. mail me waqasdaar@gmail.com Thanks in Advanced.
Back to top Profile Email Website
PerlCoder
Joined Jun 30, 2008
Posts: 148

Other Topics
Posted: Dec 22, 2008 7:38:23 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
I'm not an advanced scripter, but if you just want a fail/suceed type response, you can do this: [code=xml](program1 arg arg2 arg3 blah blah blah) && (program2 blah blah blah)[/code] Then program2 will only execute if program1 exits with successful status (code 0). Also, this is all pretty basic stuff, so you can find whatever specific info you want online pretty easily: http://www.freeos.com/guides/lsst/

PerlCoder (http://indicium.us)

Back to top Profile Email Website
waqasdaar
Joined Dec 20, 2008
Posts: 34

Other Topics
Posted: Dec 22, 2008 7:49:07 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
brother I know I can get the status of last program using $? variable. But when I checked in the program it does not have the last program exit stauts. hope you now get my point. suppose ./validate -f /home/jhon/tune.mpeg it return 1 and when I run this program ./import I want to use this status like if [ $? = 1 ] then do something.... but i does not show the last exit status of the command now you get my point?
Back to top Profile Email Website
thobbs
Joined Oct 12, 2008
Posts: 238
Location:Texas!

Other Topics
Posted: Dec 22, 2008 8:44:30 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
You can write a script that ties the other two scripts together. As in: [code=xml] #!/bin/bash ./validate -f /home/jhon/tune.mpeg if [ $? -eq 0 ]; then ./import -1 elif [ $? -eq 1 ]; then ./import -2 fi exit 0[/code] Hope that helps (and I hope this isn't why you asked that last question in the forum ([url]http://www.linux.com/forums/topic/3729[/url] -- I had a feeling you didn't really want the name of the last command executed)! [Modified by: thobbs on December 22, 2008 02:45 PM]
Back to top Profile Email Website
waqasdaar
Joined Dec 20, 2008
Posts: 34

Other Topics
Posted: Dec 22, 2008 10:33:45 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
I know I can do some thing like to merge two programs but I dont want to do that way. Is there any other way to do so ?
Back to top Profile Email Website
Khabi
Joined Apr 21, 2008
Posts: 121

Other Topics
Posted: Dec 23, 2008 6:45:53 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
This is no way to do it the way you want to. You have to either merge the two with a wrapper script, or edit to the two scripts to write and read the exit status from another file. So in the first program you run writes an exit status to something like /tmp/validate.exit (or whatever you want the file to be called) and the second one checks that file for the status and takes an appropriate measure. Those are your only two options.
Back to top Profile Email Website
waqasdaar
Joined Dec 20, 2008
Posts: 34

Other Topics
Posted: Jan 10, 2009 6:01:47 PM
Subject: Please Urgent Help needed in Bash scripting [ exit status ]
I have achieved what I want by using 'source validate.sh' command in the script. any ways thanks for your help. Cheers
Back to top Profile Email Website
Tableless layout Validate XHTML 1.0 Strict Validate CSS Powered by Xaraya