- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- awk to run execute within a script
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
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
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-27-2007 06:29 AM
тАО04-27-2007 06:29 AM
I have setup some simple code but would like to know if there is an awk alternative that if the string "Connection refused" is in $PROGMESG then exit the script.
NOSEND=`echo $PROGMSG |awk '/Connection refused/ {print}'`
if [ $NOSEND = "Connection refused" ] ; then
exit 1
fi
thanks
Solved! Go to Solution.
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 06:41 AM
тАО04-27-2007 06:41 AM
Re: awk to run execute within a script
NOSEND=`echo $PROGMSG |grep -c "Connection refused"'`
if [[ $NOSEND -gt 0 ]] ; then
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 06:44 AM
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 06:48 AM
тАО04-27-2007 06:48 AM
Re: awk to run execute within a script
echo $PROGMSG | grep "Connection Refused"
NOSEND=?*
if [ $NOSEND -eq 0 ]; then
exit 1
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 06:48 AM
тАО04-27-2007 06:48 AM
Re: awk to run execute within a script
# echo $PROGMSG | awk '$0=="Connection refused"{}' && exit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 06:57 AM
тАО04-27-2007 06:57 AM
Re: awk to run execute within a script
Why not use grep's 'quiet' option, as all you're really interested in is the return code?
echo ${PROGMSG} | grep -q 'Connection refused'
RC=${?}
if [ "${RC}" -ne "0" ]
then
echo "Exiting with rc ${RC}"
exit ${RC}
fi
If you're looking to kill the parent shell script from within awk, this should work:
awk '/Connection refused/ {system("kill $PPID")}'
This yields an exit status of '143' on my system.
PCS
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 07:00 AM
тАО04-27-2007 07:00 AM
Re: awk to run execute within a script
- Why count? Just tell grep to quit on first match.
if $(echo $PROGMSG | grep -q "Connection refused");
then
echo aap
else
echo noot
fi
fwiw,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-27-2007 07:28 AM
тАО04-27-2007 07:28 AM
Re: awk to run execute within a script
$ PROGMSG="Connection refused"
$ if [[ $PROGMSG = "Connection refused" ]]; then
echo aap
else
echo noor
fi
aap
This is often best done for a positive match, such that various and new error message are also caught as needed.
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-30-2007 07:32 PM
тАО04-30-2007 07:32 PM