- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: shell script - command grep
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
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-01-2005 05:32 AM
тАО04-01-2005 05:32 AM
I have folloging problem in script with grep:
/usr/bin/rsh 10.1.1.10 /usr/bin/grep camaro /opt/cars/log/chevrolet.log
echo $?
0
Its is Ok "camaro" exist in chevrolet.log
my problem is when execute grep
/usr/bin/rsh 10.1.1.10 /usr/bin/grep nissan /opt/cars/log/chevrolet.log
echo $?
0
the result is 0 , but word nissan no exist in chevrolet.log
the result it would have 1
as it can be the problem.
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2005 05:38 AM
тАО04-01-2005 05:38 AM
SolutionYou will have to redirect the exit status of grep to some file and then read it seperately. Something like follows.
/usr/bin/rsh 10.1.1.10 "/usr/bin/grep camaro /opt/cars/log/chevrolet.log;echo $? > /tmp/test" ; /usr/bin/rsh 10.1.1.10 "cat /tmp/test"
Anil
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2005 05:45 AM
тАО04-01-2005 05:45 AM
Re: shell script - command grep
Pete
Pete
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2005 05:45 AM
тАО04-01-2005 05:45 AM
Re: shell script - command grep
replace " for '
/usr/bin/rsh 10.1.1.10 '/usr/bin/grep camaro /opt/cars/log/chevrolet.log;echo $? > /tmp/test' ; /usr/bin/rsh 10.1.1.10 'cat /tmp/test'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2005 05:55 AM
тАО04-01-2005 05:55 AM
Re: shell script - command grep
/usr/bin/rsh 10.1.1.10 '/usr/bin/grep camaro /opt/cars/log/chevrolet.log;echo $?'
- Biswajit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО04-01-2005 07:01 AM
тАО04-01-2005 07:01 AM
Re: shell script - command grep
If you only want to know if the value is in the file and you don't care to see the line it is on, then use the -q option of grep, like this:
xyz=`remsh 10.1.1.10 'grep -q nissan /opt/cars/log/chevrolet.log;echo $?'`
echo $xyz|sed "s/\(.*\)\([0-9]\)$/\1/"
If you want to see the "output" and the "return code" then use this:
xyz=`remsh 10.1.1.10 'grep nissan /opt/cars/log/chevrolet.log;echo $?'`
This displays the output of the grep:
echo $xyz|sed "s/\(.*\)\([0-9]\)$/\1/"
This displays the output of the "return code":
echo $xyz|sed "s/\(.*\)\([0-2]\)$/\2/"
grep only has three return codes (see man grep) 0, 1 and 2.
live free or die
harry d brown jr