- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Status of Previous command ?
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
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-01-2005 04:44 AM
04-01-2005 04:44 AM
ex:
$ ls -l abc
abc not found
$
but abc not exit. So its unsuccesful.
Hence how to find out that , last command [ ls -l abc ] wasn't successful. Any command is there.
Thanks ,
Regards,
Veri.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 04:48 AM
04-01-2005 04:48 AM
Re: Status of Previous command ?
man sh-posix
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 04:48 AM
04-01-2005 04:48 AM
Re: Status of Previous command ?
STAT=${?}
if [[ ${STAT} -eq 0 ]]
then
echo "Command Ok"
else
echo "Failed; Status = ${STAT}"
fi
${?} is the return value of the last executed comand. It's a good idea to capture it in another variable because the next comand will alter ${?}. By convention, 0 indicates a good result although there are a few exceptions.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 04:53 AM
04-01-2005 04:53 AM
Re: Status of Previous command ?
if [ $? -ne 0 ]; then
echo abc not found
fi
or,
ls -l abc||echo abc not found.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 04:54 AM
04-01-2005 04:54 AM
Re: Status of Previous command ?
for i in `sed -n '/^LV/p' $CNTL |awk -F\" '{print $4}'`
do
mount |grep $i >/dev/null
if [ $? -ne 0 ]
then
echo "$i is not mounted!!!"
fi
done
Rgds...Geoff
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:09 AM
04-01-2005 05:09 AM
Re: Status of Previous command ?
Thanks for all the quick reply.
echo $? and the next two script works fine.
But I could not understand the last script by Geof.
Thanks to all,
Regards,
Veri.
---------
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:18 AM
04-01-2005 05:18 AM
SolutionFNAME="abc"
if [[ -e ${FNAME} ]]
then
echo "File ${FNAME}" exists"
else
echo "File ${FNAME} not found"
fi
You can also do things like:
if [[ -w ${FNAME} && -x ${FNAME} ]]
then
echo "File ${FNAME} exists and is writable and executable"
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:20 AM
04-01-2005 05:20 AM
Re: Status of Previous command ?
#!/bin/sh
#
# script to check all file systems are mounted
# gwild
CNTL=/etc/cmcluster/IPRDBCI/iprdbci.cntl
for i in `sed -n '/^LV/p' $CNTL |awk -F\" '{print $4}'`
do
# ok - here I check to see if a filesystem $i is mounted
# don't want output - so I send it to /dev/null
mount |grep $i >/dev/null
# however - $? still has the return code
# so, I check to see if it is not equal to 0 (successs)
if [ $? -ne 0 ]
# if it isn't then echo the fact that it isn't mounted
then
echo "$i is not mounted!!!"
fi
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-01-2005 05:47 AM
04-01-2005 05:47 AM
Re: Status of Previous command ?
ex: # ps -ef | grep pmon
# userdel abc
and thanks for showing the built in test for file testing , if exists , writable or executable etc.
Thanks so much. Thanks Geof and all who replied.
Points Assigned **
Regards,
Veri.