- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Question with my awk section
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
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
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
06-22-2012 07:18 PM - edited 10-05-2012 05:26 PM
06-22-2012 07:18 PM - edited 10-05-2012 05:26 PM
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-22-2012 10:59 PM
06-22-2012 10:59 PM
Re: awk exit status
>all I need is either exit with 0 or non zero
END { if (FOUND != 1) {print " TSM Server = Not configured"; exit 1}}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2012 04:39 AM
06-23-2012 04:39 AM
Re: awk exit status
Thanks for the suggesstion I have tried putting exit 1 where u suggessted and simulated the test again but script doesn't exist with non zero ??
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2012 04:12 PM
06-23-2012 04:12 PM
Re: awk exit status
>but script doesn't exit with non zero?
Please paste your script so we can verify.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-23-2012 11:41 PM - edited 06-23-2012 11:42 PM
06-23-2012 11:41 PM - edited 06-23-2012 11:42 PM
Re: awk exit status
> Above is the excerpt again, script itself works fine but doesn't exit with non zero code even when it is not registered.
I don't see my exit 1. I also don't see what is after awk.
/usr/bin/dsmc q se | awk '
/Server Name/ {
print " TSM Server = " $NF
FOUND=1
}
END {
if ( FOUND != 1 ) {
print " TSM Server = Not configured"
exit 1
}
}'
if [ $? -ne 0 ]; then
exit 1
fi
>Here is set -x for your perusal,
I see more than what you have in your script.
>exit status is 1 but it still goes ahead
You have to check for it. Or use "set -e".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2012 02:22 AM
06-24-2012 02:22 AM
Re: awk exit status
just to be precise with my code as per my previous post
some_command | awk '
/retrive_this_value/ { # if the value is none ie blank then exit the program but it doesn't exit and goes further, i don't know how to check the blank character here , i tried "" but obviously that didn't work for me
print " Virtual Memory = " $NF
FOUND=1
}
END {
if ( FOUND != 1 ) {
print " Virtual Memory = Not assigned--exiting program"
exit 2
}
}'
if [ $? -ne 0 ]; then
exit 2
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2012 01:52 PM
06-24-2012 01:52 PM
Re: awk exit status
>this is great help, I have got what I wanted.
If you are happy with the answers you were given, please click on the Kudos stars of each helpful post.
>lspath -l hdisk1 -s Enabled|grep fscsi|grep Enabled
You can optimize this to one grep:
lspath -l hdisk1 -s Enabled | grep "Enabled.*fscsi"
You can use "grep -c" to count and with a real shell should use $() vs ``:
DSKPATH=$(lspath -l $DISK -s Enabled | grep -c "Enabled.*fscsi") # this counts for 2 paths 1 per adapter
if [ $DSKPATH -lt 2 ]; then
echo "We don't have dual paths--exiting program now--"
exit 1
fi
done
echo "We have dual paths for all disks"
>parameter # space - means there is no value assigned, and if it is true then simply exit the program)?
You could use:
if [ "$parameter" = "" ]; then
exit
fi
>if the value is none ie blank then exit the program
If you want to check for an empty line, you can do:
/^#/ { exit 1}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2012 03:41 PM
06-24-2012 03:41 PM
Re: awk exit status
Thanks again , you have been great assist, I will test it and let you know if I have any hiccup but this should now resolve my hiccups :)
I've clicked on start to assign points but it only seems to add 1 point, is this maximum we can assign ?
once i have tested it i will close this thread by marking as "accept this as solution", i may have to ask some more question tho...
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2012 01:05 PM - edited 06-25-2012 07:28 PM
06-25-2012 01:05 PM - edited 06-25-2012 07:28 PM
Re: awk exit status
>it only seems to add 1 point, is this maximum we can assign?
Yes, one per post.
>return 1 # not sure if this is where I need return or else where please correct
Yes, this will work for functions.
>if [ "$NF" = "" ]; then # How to check - :
Why bother? If you don't get a good exit status (0), you didn't find what you wanted.
If you do want to check, you can just check in awk for:
if ($NF == ":")
>return 0 # Please correct
SInce you aren't in an awk function, I would just use: exit 0
(In fact, awk will not let you use return unless you are in a function.)
># Main and do I need to execute my functions below?
Yes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-25-2012 02:57 PM
06-25-2012 02:57 PM
Re: awk exit status
Thanks again few more quest, my questions are next to # below
>return 1 # not sure if this is where I need return or else where please correct, i will test this today tho
Yes, this will work for functions.
>if [ "$NF" = "" ]; then # How to check - :
Why bother? If you don't get a good exit status (0), you didn't find what you wanted.
If you do want to check, you can just check in awk for:
if ($NF == ":") # So this check goes into the same place where I'm currently checking in my script
>return 0 # Please correct
SInce you aren't in an awk function, I would just use: exit 0
# Even if I'm not in awk i need to check return 1 or return 0, so i can make it uniform in the script
I guess i can replace return 1 with exit 1 which i originally had but where to check return 0 tho ?
># Main and do I need to execute my functions below?
# The way i have stuff in my main, is this the correct way of checking it or am i missing anything such as executing function etc ? please correct
Yes.