- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - HP-UX
- >
- Languages and Scripting
- >
- Re: AND, OR with IF and GREP - statements in shell...
-
- Forums
-
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
- HPE Blog, Austria, Germany & Switzerland
- Blog HPE, France
- HPE Blog, Italy
- HPE Blog, Japan
- HPE Blog, Middle East
- HPE Blog, Russia
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
-
Blogs
- Advancing Life & Work
- Advantage EX
- Alliances
- Around the Storage Block
- HPE Blog, Latin America
- HPE Blog, Middle East
- HPE Blog, Saudi Arabia
- HPE Blog, South Africa
- HPE Blog, UK & Ireland
- HPE Ezmeral: Uncut
- OEM Solutions
- Servers & Systems: The Right Compute
- Tech Insights
- The Cloud Experience Everywhere
-
Information
- Community
- Welcome
- Getting Started
- FAQ
- Ranking Overview
- Rules of Participation
- Tips and Tricks
- Resources
- Announcements
- Email us
- Feedback
- Information Libraries
- Integrated Systems
- Networking
- Servers
- Storage
- Other HPE Sites
- Support Center
- Aruba Airheads Community
- Enterprise.nxt
- HPE Dev Community
- Cloud28+ Community
- Marketplace
-
Forums
-
Blogs
-
Information
-
English
- 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
- Email to a Friend
- Report Inappropriate Content
01-13-2011 03:59 AM
01-13-2011 03:59 AM
Please suggest about:
1. AND, OR operations inside an IF condition
2. AND, OR operations inside GREP
AND and OR operations give confusions and issues all the times(which braket"(" or "[[" or, ,,etc,...). can you please write how to use them with simple examples.
ISSUE: i have this output in a file(output-file). i would like to run an opcmsg if either rds, crs, mmd or kms is down.
OUTPUT-FILE:
**************
oper@corvette:/home/oper=>omnisv -status
ProcName Status [PID]
===============================
rds : Down
crs : Active [9569]
mmd : Active [9566]
kms : Active [9567]
omnitrig: Active
uiproxy : Active [9571]
===============================
Status: At least one of Data Protector relevant processes/services is not running.
**************
i wrote like this:
RDS=`grep -c rds output-file | grep -c Down`
CRS=`grep -c crs output-file | grep -c Down`
MMD=`grep -c mmd output-file | grep -c Down`
KMS=`grep -c kms output-file | grep -c Down`
if[[ $RDS -eq 1 || $CRS -eq 1 || $MMD -eq 1 || $KMS -eq 1 ]]
then
echo "At least one of Data Protector relevant processes/services is not running."
fi
Solved! Go to Solution.
- Tags:
- grep
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 04:08 AM
01-13-2011 04:08 AM
Re: AND, OR with IF and GREP - statements in shell scripting
grep -i down
Just a thought,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 04:09 AM
01-13-2011 04:09 AM
Re: AND, OR with IF and GREP - statements in shell scripting
grep -i down
should read
grep -i down
Boy I hate giving up coffee....
/rcw
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 04:24 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 04:36 AM
01-13-2011 04:36 AM
Re: AND, OR with IF and GREP - statements in shell scripting
ya, presently i am doing the same thing - i am grep'ing for 4 "Active" and if its less, i am running few other commands.
issue is that the other two processes uiproxy and omnitrig need not be monitored.. i want to monitor only 4 processes, that is the issue.
Also please advice how to use AND and OR operators with IF and GREP.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 05:03 AM
01-13-2011 05:03 AM
Re: AND, OR with IF and GREP - statements in shell scripting
You question was:
AND and OR operations give confusions and issues all the times(which braket"(" or "[[" or, ,,etc,...). can you please write how to use them with simple examples.
..take a look at Jose wrote it and you have a good answer of your request for a simple example..
Rgrds,
Rita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 05:05 AM
01-13-2011 05:05 AM
Re: AND, OR with IF and GREP - statements in shell scripting
the script now
RDS=`grep rds testfile | grep -c Down`
CRS=`grep crs testfile | grep -c Down`
MMD=`grep mmd testfile | grep -c Down`
KMS=`grep kms testfile | grep -c Down`
if [ "${RDS}${CRS}${MMD}${KMS}" != "0000" ] i
then
echo "At least one process is not running"
fi
between, still you can reply about -
How to use to AND and OR, with GREP and IF ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 05:09 AM
01-13-2011 05:09 AM
Re: AND, OR with IF and GREP - statements in shell scripting
you have a mistake in your script.
"grep -c" return a count of matching lines.
You should replace:
RDS=`grep -c rds output-file | grep -c Down`
CRS=`grep -c crs output-file | grep -c Down`
MMD=`grep -c mmd output-file | grep -c Down`
KMS=`grep -c kms output-file | grep -c Down`
by (remove 1st "-c"):
RDS=`grep rds output-file | grep -c Down`
CRS=`grep crs output-file | grep -c Down`
MMD=`grep mmd output-file | grep -c Down`
KMS=`grep kms output-file | grep -c Down`
My suggestion:
if grep -qE '^(rds|crs|mmd|kms) : Down' output-file
then
echo ...
fi
Regards,
Mounaam
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 05:10 AM
01-13-2011 05:10 AM
Re: AND, OR with IF and GREP - statements in shell scripting
RDS=`cat output-file|grep -q ^"rds : Down"|echo $?`
CRS=`cat output-file|grep -q ^"crs : Down"|echo $?`
MMD=`cat output-file|grep -q ^"mmd : Down"|echo $?`
KMS=`cat output-file|grep -q ^"kms : Down"|echo $?`
if [ "${RDS}${CRD}${MMD}${KMS}" != "0000" ]
then
echo "At least one of Data Protector relevant processes/services is not running."
fi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
01-13-2011 07:20 PM
01-13-2011 07:20 PM
Re: AND, OR with IF and GREP - statements in shell scripting
For 'and' and 'or' operators within an 'if' condition, you should read the section of the 'sh-posix(1) manpages entitled "conditional expressions" as well as the manpages for 'test(1)'.
The 'grep' command can perform regular expression alternation (an 'or') like this (using your example:
# grep -E "rds : Down|crs : Down|mmd : Down|mks : Down" filename && echo "at least one down" || echo "all ok"
...or with :
grep -e "rds : Down" -e "crs : Down" -e "mmd : Down" -e "mks : Down" filename && echo "at least one down" || echo "all ok"
Regards!
...JRF...
Hewlett Packard Enterprise International
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP