Skip to ContentSkip to Footer
Start of content
- Community Home
- >
- Servers and Operating Systems
- >
- Operating System - Linux
- >
- General
- >
- pid in shell script again...
General
-
- 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, Latin America
- 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
Topic Options
- 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
06-19-2007 12:24 AM
06-19-2007 12:24 AM
pid in shell script again...
hi if thr r two process id s from the following command how to pick the second process id.
l=`ps ux | awk '/mojo/ && !/awk/ {print $2}'`
echo $l;
And if the o/p is
17665
17867
how to store this in an array and retrieve each one of thm whn needed
l=`ps ux | awk '/mojo/ && !/awk/ {print $2}'`
echo $l;
And if the o/p is
17665
17867
how to store this in an array and retrieve each one of thm whn needed
- Tags:
- PS
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-19-2007 01:50 AM
06-19-2007 01:50 AM
Re: pid in shell script again...
Hi
l=$(ps -C mojo -o pid= | sed -n "2p" )
rgds
HGH
l=$(ps -C mojo -o pid= | sed -n "2p" )
rgds
HGH
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-19-2007 04:10 AM
06-19-2007 04:10 AM
Re: pid in shell script again...
Hi
You can write a perl script as below.
#!/usr/local/bin/perl
@test = `ps ux | awk '/mojo/ && !/awk/ {print $2}'`;
foreach $test (@test)
{
print "$test\n";
}
save it to a file by name pid.pl
and chmod +x pid.pl
and invoke it
./pid.pl
HTH
Padma
You can write a perl script as below.
#!/usr/local/bin/perl
@test = `ps ux | awk '/mojo/ && !/awk/ {print $2}'`;
foreach $test (@test)
{
print "$test\n";
}
save it to a file by name pid.pl
and chmod +x pid.pl
and invoke it
./pid.pl
HTH
Padma
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
06-19-2007 05:58 AM
06-19-2007 05:58 AM
Re: pid in shell script again...
#!/bin/bash -vx
# Pick 2nd (last) PID.
l=`ps ux | awk '/root/ && !/awk/ {print $2}' | tail -1`
echo $l
# Place PIDs in array ary
l=`ps ux | awk '/root/ && !/awk/ {print $2}'`
ary=($l)
Vic
# Pick 2nd (last) PID.
l=`ps ux | awk '/root/ && !/awk/ {print $2}' | tail -1`
echo $l
# Place PIDs in array ary
l=`ps ux | awk '/root/ && !/awk/ {print $2}'`
ary=($l)
Vic
There are 10 kinds of people, one that understands binary and one that doesn't.
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
End of content
United States
Hewlett Packard Enterprise International
Communities
- Communities
- HPE Blogs and Forum
© Copyright 2021 Hewlett Packard Enterprise Development LP