- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Regarding ps command
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
тАО09-06-2006 07:47 PM
тАО09-06-2006 07:47 PM
I do the below from unix shell prompt
ps -eaf | grep -i rpt
I want to put this one in a shell script and do the above check. how can i do it?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 07:55 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:09 PM
тАО09-06-2006 11:09 PM
Re: Regarding ps command
ps: illegal option -- C
usage: ps [-edaflP] [-u ulist] [-g glist] [-p plist] [-t tlist] [-R prmgroup]
Also i want to see whether the daemon runs under any user id.
I am getting the below output if i ran when the daemon process is not running
ps -eaf | grep -i test1.sh
hal 1531 1506 1 06:04:35 ttyp4 0:00 grep -i test1.sh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:18 PM
тАО09-06-2006 11:18 PM
Re: Regarding ps command
UNIX95= ps -C"process_name"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:31 PM
тАО09-06-2006 11:31 PM
Re: Regarding ps command
RAC's method using the UNIX95 behavior of 'ps' to look for a process by name is guaranteed to match the process's name. Using 'grep' without regular expression anchors in the expression can lead to finding processes you *don't* intend to find!
*However*, don't export UNIX95 into your environment. You may find that the behavior of commands other than 'ps' change in unexpected ways!
By doing:
# UNIX95= ps -C mything -o pid=
...for example, you arm UNIX95 behavior *only* for the duration of the command line -- a safe mode. Note that a space follows the equal sign and no semicolon appears before the 'ps'.
In the example, above, if there was a process named "mything", one line of output would be returned containing the process pid. The equal sign after the keyword "pid" suppresses the normal column header that would appear over it in its absence.
The manpages for 'ps' document and provide more information for these behaviors.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 11:43 PM
тАО09-06-2006 11:43 PM
Re: Regarding ps command
If you really want to go the 'ps ... | grep ...' route, you must exclude the grep process itself from the results:
# ps -ef | grep -i test1.sh | grep -v grep
As RAC suggested, "ps -C
# UNIX95=1 ps -o comm= -C test1.sh
will elimate the header line.
#!/usr/bin/sh
UNIX95=1 ps -o comm= -C test1.sh
if [[ ${?} -ne 0 ]]
then
echo "test1.sh not running!" >&2
exit 1
fi
...What to do if test1.sh is running here...
exit 0
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-08-2006 07:52 PM
тАО09-08-2006 07:52 PM
Re: Regarding ps command
==> UNIX95=ps -C"test1.sh"
ksh: -Ctest1.sh: not found
==> UNIX95=ps -C test1.sh
ksh: -C: not found
==> UNIX95=ps -C "test1.sh"
ksh: -C: not found
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2006 12:30 AM
тАО09-09-2006 12:30 AM
Re: Regarding ps command
You need a space character (or tab) *after* the equal sign and *before* the 'ps' command:
# UNIX95= ps -C test1.sh
...NOT:
# UNIX95=ps -C test1.sh
Since whitespace is difficult to see on the Forum, cut-and-paste the above renditions if you need to see this.
Note that enclosing the program name argument for the '-C' switch is unnecessary.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-09-2006 11:59 AM
тАО09-09-2006 11:59 AM
Re: Regarding ps command
It may help to understand this temporary construct by using the command this way:
UNIX95=1 ps -o pid= -o args= -C test.sh
I have posted this answer using the Retain formatting option so you can better see the spaces. Again this is all on 1 line.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2006 03:35 AM
тАО09-14-2006 03:35 AM
Re: Regarding ps command
1) The below command is working. Hope it will work even if the test.sh runs under another unix user id or root user id?
UNIX95= ps -C test1.sh
2. I tried this one and it gives some error
UNIX95= ps -C test1.sh pid=
ps: Unknown option (pid=).
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-14-2006 04:32 AM
тАО09-14-2006 04:32 AM
Re: Regarding ps command
You need:
# UNIX95= ps -C test1.sh -o pid
...whereas you had:
# UNIX95= ps -C test1.sh pid=
...with the '-o ' to signal that the 'pid=' was the option.
Similarly, if you want to add additional fields (here, without labels), repliate the '-o' switch like:
# UNIX95= ps -C vhand -o pid= -o ppid= -o comm=
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-15-2006 12:24 AM
тАО09-15-2006 12:24 AM
Re: Regarding ps command
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-17-2006 11:16 PM
тАО09-17-2006 11:16 PM