- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Re: loop on ps -ef output
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
тАО08-05-2010 11:00 AM
тАО08-05-2010 11:00 AM
I'm doing this
for databases in $(ps -ef | grep -i ora_pmon | awk '{print $9}')
> do
> echo $databases
> done
Result is:
ora_pmon_WSLPREP1
ora_pmon_HCMPRE21
ora_pmon_WMTPREP1
ora_pmon_RATPREP1
-i
ora_pmon_PSCPREP1
ora_pmon_AUSTRNG1
ora_pmon_AUSPREP1
1. How to Eliminate the -i (in the loop because grep command is running)
2. How to eliminate "ora_pmon_" and "1" to have only my instance name like this:
WSLPREP
HCMPRE2
WMTPREP
RATPREP
PSCPREP
AUSTRNG
AUSPREP
Let me know if you have a solution.
Thanks in advance
Regards
Den
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2010 01:47 PM
тАО08-05-2010 01:47 PM
Re: loop on ps -ef output
echo $databases |awk -F'_' '{print $3}'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2010 02:01 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2010 02:29 PM
тАО08-05-2010 02:29 PM
Re: loop on ps -ef output
$(ps -ef |grep -i ora_pmon | grep -v grep | awk '{print substr($9,10,length($9) - 10)}')
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2010 03:27 PM
тАО08-05-2010 03:27 PM
Re: loop on ps -ef output
There's no real reason to call grep multiple times, nor even to call awk over and over again just for simple string manipulation. Here's one way to do it:
--
#! /bin/bash
for database in $(ps -ef |grep [o]ra_pmon); do
printf '%s\n' "${database##*_}"
done
--
This way, you only run 'ps' once and 'grep' once, and printf is a shell builtin in bash (even if there is a binary printf in the filesystem, bash won't use it unless you specify the full pathname.)You could probably do the whole thing with shell builtins and the /proc filesystem, but the benefit would be negligible in most cases.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2010 03:38 PM
тАО08-05-2010 03:38 PM
Re: loop on ps -ef output
You might try this:
--
#! /bin/bash
ps -ef |grep [o]ra_pmon | while read db; do
printf '%s\n' "${db##*_}"
done
--
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 04:25 AM
тАО08-06-2010 04:25 AM
Re: loop on ps -ef output
This works for me notice {print $8} you may need to adapt this to your output.
for databases in $(ps -ef | grep -i [o]ra_pmon |grep -v "grep" | awk '{print $8}')
> do
> echo $databases
> done
enjoy life.
Jean-Pierre Huc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 05:43 AM
тАО08-06-2010 05:43 AM
Re: loop on ps -ef output
--------------------------
This works for me notice {print $8} you may need to adapt this to your output.
for databases in $(ps -ef | grep -i [o]ra_pmon |grep -v "grep" | awk '{print substr($8,10)}')
> do
> echo $databases
> done
--------------------------
if you need to replace $8 by $9
Hoping this is a little clear.
enjoy life.
Jean-Pierre Huc
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 06:06 AM
тАО08-06-2010 06:06 AM
Re: loop on ps -ef output
Thanks Guys
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2010 10:22 AM
тАО08-06-2010 10:22 AM
Re: loop on ps -ef output
> [...]
So, you completely missed the reason for
using that "[o]" construct in "[o]ra_pmon"?
> This works for me [...]
You should try it without the second grep
command.