- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Simple Script Help
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 06:33 AM
04-25-2002 06:33 AM
9 Months of working on WIN2K boxes has left my scripting skills rusty, which were never good to begin with but anyway.. This is a simple problem but I cannot find the answer. Any help would be appreciated.
su - dmadmin -c dba/stop.all
sleep 45
if [[ $? = 0 ]]
I do not want to test the return code of the sleep command at this point. I want to test the code of the previous line. I think it may be $! but I am not sure.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 06:39 AM
04-25-2002 06:39 AM
Solution1. Return Code Saving
su - dbadmin -c 'cmd'
export RC=$?
sleep 45
if (( $RC != 0 ))
then
fi
This will grab the return code for you and save it in $RC.
2. What return code
The above script will only capture the result of the 'su' command, NOT the result of the 'cmd' command. This is a problem that has dogged sysadmins for yonks. I get around this by putting the following inside the command 'cmd; print "RTN "$?'
What U then do is capture the output, grep for keyword 'RTN' and cut out the second field (cut -d' ' -f2). This will actually capture the result of the 'cmd' for future analysis.
Share and Enjoy! Ian
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 06:47 AM
04-25-2002 06:47 AM
Re: Simple Script Help
There is no guarantee that you will get a return code of "1" if one of the processes in your "stop.all" fails as $? will return 0 as su completes successfully irrespective of the execution unless you explicitly return a different number in your stop.all script.
Your best bet may be to check if all the processes are stopped like
num_of_procs=`ps -ef|grep dmadmin|grep -v grep|wc -l`
if [ $num_of_procs != 0 ]
then
kill_something
fi
The above is only one way. There are thousand other ways of doing it.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 06:50 AM
04-25-2002 06:50 AM
Re: Simple Script Help
i don't know how to get the previous line code, but hope this may help u.
if [ $? -eq 0 ]
then
x=ok
else
x=not
fi
sleep 10
if [ "$x" = "ok" ]
then
regds
ravi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2002 07:02 AM
04-25-2002 07:02 AM
Re: Simple Script Help
Then you will ahve to put the test condition in a loop , first run the command then check for the variable and put a test condition and the the commnad then sleep and put this all in a loop .
Like
su - dmadmin -c dba/stop.all
while true
do
export A=`ps -aef | gerp stop.all |wc -l `
if [ $A = 0 ]
then
command
exit
fi
sleep 45
done
may be this will help you
Manoj Srivastava