- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- grep question ..
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
08-18-2001 12:55 PM
08-18-2001 12:55 PM
we have a process call tgu_stats
Example 1. Command and output
#ps -ef|grep tgu*
root 1884 29789 0 15:52:42 pts/td 0:00 grep tgu_stats.log
Example 2. Command and output.
#ps -ef|grep tgu
root 1709 29789 1 15:51:48 pts/td 0:00 grep tgu
root 680 1 23 15:46:04 pts/td 0:04 tgu_stats
Why when I grep for tgu* I dont get back the tgu_stats proces? And when I grep for tgu I dont get back tgu_stats.log?
Thanks
Richard
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 01:13 PM
08-18-2001 01:13 PM
SolutionYou are confused about the way grep works. You don't need the '*' at all.
In example 1)
The tgu* was expanded by the shell to look for all files beginning with tgu so that your actual grep command was grep tgu_stats.log
and the only process it found was you grep
command itself.
In example 2) tgu_stats.log is a FILE not a PROCESS sops would not find it.
To do this correctly:
ps -ef | grep "tgu" | grep -v "grep"
The last grep gets rid of the grep process itself.
I hope that clears it up, Clay
#ps -ef|grep tgu*
root 1884 29789 0 15:52:42 pts/td 0:00 grep tgu_stats.log
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 01:22 PM
08-18-2001 01:22 PM
Re: grep question ..
Try with ps -ef|grep 'tgu*'
and see if you get any difference.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 01:31 PM
08-18-2001 01:31 PM
Re: grep question ..
the shell tries to spawn tgu*. If your current directory has tgu_stats.log, then you won't get the correct output.
So, go to another directory where you don't have anyfile starting with tgu and run this command, you will get the correct output like what you get with ps -ef|grep 'tgu*'
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 03:00 PM
08-18-2001 03:00 PM
Re: grep question ..
Another way to just grep your process is
ps -ef |grep [t]gu
This greps for any process starting with t followed by gu and thereby avoids using another grep (for grep -v) but then its a preference issue.
Ofcourse as far as your question is concerned about not getting the expected output when you use tgu*, that is because of the shell expansion.
-HTH
I am RU
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 04:45 PM
08-18-2001 04:45 PM
Re: grep question ..
ps -ef | grep -v grep | grep -i
where something is what you are looking for. grep -v grep removes the grep process for tgu, but it also removes a process called grepping and a user name grepguru, which may not be desired.
So to find all processes that have a specific basename (the process name without any leading directories such as /usr/contrib/bin/tgu), use the PowerPill for ps called UNIX95:
UNIX95= ps -fC tgu_stats
No grep needed, and most important, it returns ONLY tgu_stats and not tgu_stats1, etc. Check out the difference between:
ps -ef | grep sh
UNIX95= ps -fC sh
Wow, what a difference. The second form (which activates the -C option in XPG4 mode) is really what we want.
Another feature of the PowerPill option is the ability to create a customized output format. SO if you don't need start-time (which varies in format), you can eliminate it. Consider this form:
UNIX95= ps -C sh -o ruser,pid,args
Now, very simple parsing can be done for the desired information. See man ps
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-18-2001 10:28 PM
08-18-2001 10:28 PM
Re: grep question ..
I also prefer "ps -ef | grep [w]hatever" above "ps -ef | grep -v grep | grep whatever".
good one Ramesh!, sorry Bill ;)
regards,
Thierry.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2001 12:02 AM
08-19-2001 12:02 AM
Re: grep question ..
Also, Richard's problem will still exist if we use grep -v grep option. As long as he has tgu_stats.log or anything that starts with tgu in his current directory, he is never going to get tgu_stats in his grep tgu* command.
He will get correct output only when he does
1. ps -ef|grep 'tgu*'
2. Go to some other directory and execute grep 'tgu*' where there are no files that are starting with tgu*
3. The rocking way of using UNIX95
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2001 06:07 AM
08-19-2001 06:07 AM
Re: grep question ..
To remove the grep process being displayed so
ps -ef | grep [t]gu
with this we need not use grep -v grep
...BPK...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-19-2001 09:14 AM
08-19-2001 09:14 AM
Re: grep question ..
I like Bill's solution but the "Key" is that the process you are looking for should be the basename.
for example if you have a process called "tgu tgu_stats"
executing UNIX95= ps -fC tgu_stats will not return any output, where as UNIX95= ps -fC tgu, will return the desired output.
But my suggestion Richard is to avoid using * when grepping for anything and always enclose in ' ' to avoid shell misinterpretation.
-Regards
I am RU