LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-01-2007, 11:16 PM   #1
sharathkv25
Member
 
Registered: Jul 2006
Distribution: HP-UX
Posts: 46

Rep: Reputation: 15
Ksh Script Help


Hi,

I would like to do this in a shell script.

ps -ef | grep "java TPCISDae" | grep -v grep

How do I do this?

This is not working.

Code:
mstat=`ps -ef | grep "java TPICSDae" | grep -v grep`
 
Old 02-02-2007, 01:29 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
looks ok to me, what error are you getting?
 
Old 02-02-2007, 05:19 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
If you are only looking for PID's (provided pgrep is available) a shorter form could be "mstat=`pgrep -f "java.*TPICSDae"`".
 
Old 02-02-2007, 07:28 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
I do it like this:

Code:
mstat=`ps -ef | grep "[j]ava TPICSDae"
 
Old 02-02-2007, 07:42 AM   #5
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
pgrep is not very good on solaris

something to watch out for - pgrep is not very good on solaris
dunno what you run on...

i.e. it has unexpected behaviour on a long command name,
observe:

Code:
billy$ cp /usr/bin/sleep ./very_long_command_name

billy$very_long_command_name 200 &
[2]     3103
billy$very_long_command_name 200 &
[3]     3104

billy$ pgrep very_long_command_name      
billy$ pgrep very_                 
3104
3103
it fails to pick it up if you use the full name,
 
Old 02-02-2007, 07:43 AM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Good call, case.
Still 'pgrep' is more efficient, two tasks combined into one binary,: pgrep -f "[j]?ava.*TPICSDae".
 
Old 02-02-2007, 07:51 AM   #7
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
pgrep is not very good on solaris
Nice to know but I didn't seen no --with-explicit-compat flag in the OP's questions.
Since we *are* at LQ I assert --with-compat="GNU/Linux" unless stated otherwise.


it has unexpected behaviour on a long command name
What if you match with "pgrep -f "anchor.*anchor"" where anchor obviously are parts of very_long_command_name's argv[whatever]?

Last edited by unSpawn; 02-02-2007 at 07:53 AM.
 
Old 02-02-2007, 08:07 AM   #8
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
granted, but i thought i'd mention it as it caught me out badly a few months ago at work.
and as the OP is talking ksh I thought perhaps he's on a unix.

ahem!
Quote:
This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
 
Old 02-02-2007, 09:43 AM   #9
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
as the OP is talking ksh I thought perhaps he's on a unix
Seems we : ${things:="GNU/Linux"} differently, oh well. If the OP got what he needs then all is OK.


Quote:
ahem!
Quote:
This forum is for all programming questions. The question does not have to be directly related to Linux and any language is fair game.
Anyway, I quote your quote and raise you ten ;-p
 
Old 02-02-2007, 09:51 AM   #10
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
so we can assume we are both a bit bored at work
 
Old 02-02-2007, 10:28 AM   #11
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Maybe you can, I can not.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
help w/ksh script ShaqDiesel Programming 2 01-12-2007 02:04 PM
ksh math script SeT Programming 10 10-13-2004 08:06 AM
Can somebody help me with a ksh script? twentymil AIX 7 01-21-2004 09:55 AM
ksh script problem pldobs Programming 2 12-24-2003 11:38 PM
KSH script AquamaN Programming 2 12-08-2003 11:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration