LinuxQuestions.org
Review your favorite Linux distribution.
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 08-05-2013, 03:27 PM   #1
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Rep: Reputation: Disabled
orphan ksh in top output ?


Hi Friends - I am trying to write a script that would check for orphan ksh processes from top command and alert the team.

Here is the sample output of top with Linux flavor

more topCPU.log
%CPU %MEM VSZ RSS USER STIME PID COMMAND
0.0 0.0 10372 560 root Jun10 1 init [5]
0.0 0.0 0 0 root Jun10 2 [migration/0]
0.0 0.0 0 0 mega Jun10 3 ksh
0.0 0.0 0 0 appuser Jun10 4 -ksh
0.0 0.0 0 0 root Jun10 5 -ksh


I wrote a snippet that would basically outputs the entry

Example:
=> more topCPU.log | awk '{print $8}' | grep "^-ksh$"
-ksh
-ksh

How could I get entire line ? OR any better approach ?

Thanks
 
Old 08-05-2013, 06:53 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,005
Blog Entries: 54

Rep: Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763Reputation: 2763
Code:
\ps -o ppid,args -C -ksh|awk '{if ($1 == 1) {print }}'
or
Code:
pgrep -P 1 -f -- "-ksh"
?
 
Old 08-06-2013, 09:43 AM   #3
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hi UnSpawn -thanks for your reply

I dont want to find out through ps/pgrep commands, coz we have several hosts and end up running several instances of script

Just want to grep from log files which have entries of ksh processes
 
Old 08-06-2013, 09:50 AM   #4
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Code:
more topCPU.log
=>
%CPU %MEM     VSZ     RSS      USER        STIME     PID COMMAND
 3.9  0.0  415148    7032      root        Jun10    6392 bin/dna -server.host
 0.0  0.0   10372     560      root        Jun10       1 /bin/ksh /apps/sa/tools/monitor.ksh
 0.0  0.0       0       0      mega        Jun10       2 /bin/ksh /apps/sa/tools/abc.ksh
 0.0  0.0       0       0      user        Jun10       3 ksh
 0.0  0.0       0       0      root        Jun10       4 [watchdog/0]
 0.0  0.0       0       0      root        Jun10       5 [migration/1]
 0.0  0.0       0       0      root        Jun10       6 [ksoftirqd/1]
 0.0  0.0       0       0      mega        Jun10       7 ksh
when I grep it, its getting all ksh processes instead of just ksh or -ksh

Desired output:
0.0 0.0 0 0 user Jun10 3 ksh
0.0 0.0 0 0 mega Jun10 7 ksh

Any help is appreciated

Thank you
 
Old 08-06-2013, 10:12 AM   #5
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Try grep -e ' -\?ksh$' topCPU.log.
 
Old 08-06-2013, 10:18 AM   #6
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
well, no luck
 
Old 08-06-2013, 10:34 AM   #7
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
What do you mean, no output? You copy/pasted it when executing?
 
Old 08-06-2013, 10:43 AM   #8
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
yeah, there is no output

Code:
:
=> grep -e '-\?ksh$' topCPU.log
:

=> grep ksh topCPU.log
 3.9  0.0   10004    1436      user        Jun25   26900 /bin/ksh /apps/sa/tools/monitor.ksh
 0.0  0.0       0       0      user        Jun10       7 ksh
 0.0  0.0       0       0      root        Jun10      16 -ksh
 0.0  0.0       0       0      root        Jun10      18 ksh
 1.8  0.0    9884    1452      user        01:15    3375 /bin/ksh /apps/sa/tools/abc.ksh
 0.0  0.0       0       0      root        Jun10      17 -ksh
 1.9  0.0    9876    1440      user        03:00   18645 /bin/ksh /apps/sa/adhoc/ch
 3.8  0.0    9884    1452      user        05:15   14884 /bin/ksh /apps/sa/tools/lo
:
=>
 
Old 08-06-2013, 10:49 AM   #9
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Code:
'-\?ksh$' topCPU.log
There's supposed to be a space between ' and -. You didn't copy it well.
Try this one too if it doesn't work as the shell might parse it differently.
Code:
grep -e " -\\?ksh$" topCPU.log
 
Old 08-06-2013, 10:57 AM   #10
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Hello - I tried with and without space earlier, as mentioned it was not able to find the entries in the log file

Tried with double quotes too, no output :-(
 
Old 08-06-2013, 11:37 AM   #11
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,245
Blog Entries: 15

Rep: Reputation: 233Reputation: 233Reputation: 233
Try these variations as well:
Code:
grep -e " -?ksh$" topCPU.log
grep -e " -\\?ksh$" topCPU.log
grep -e "[[:blank:]]-?ksh[[:blank:]]*$" topCPU.log
grep -e "[[:blank:]]-\\?ksh[[:blank:]]*$" topCPU.log
grep -e "[[:space:]]-?ksh[[:space:]]*$" topCPU.log
grep -e "[[:space:]]-\\?ksh[[:space:]]*$" topCPU.log
grep -e " -?ksh *$" topCPU.log
grep -e " -\\?ksh *$" topCPU.log
If nothing still works, please give us the output of
Code:
echo grep -e " -\\?ksh *$" topCPU.log
 
1 members found this post helpful.
Old 08-06-2013, 12:23 PM   #12
megatron521
LQ Newbie
 
Registered: Aug 2013
Posts: 11

Original Poster
Rep: Reputation: Disabled
Thanks alot, it worked
All the 3 below commands were giving expected output
Code:
grep -e "[[:blank:]]-\\?ksh[[:blank:]]*$" topCPU.log
grep -e "[[:space:]]-\\?ksh[[:space:]]*$" topCPU.log
grep -e " -\\?ksh *$" topCPU.log

output:
 0.0  0.0       0       0      root        Jun10       7 ksh
 0.0  0.0       0       0      root        Jun10      16 -ksh
 0.0  0.0       0       0      root        Jun10      18 ksh
 0.0  0.0       0       0      root        Jun10      17 -ksh
Goodday
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
How to mix orphan an non orphan child ? hervek Programming 2 01-28-2013 04:37 AM
Ps & top different output vicky007aggrwal Linux - Newbie 1 09-18-2012 01:20 AM
top output grob115 Linux - Server 18 01-25-2011 01:19 PM
KSH Output/Strip portion of file in HP-UX austin881 Programming 2 10-08-2009 12:53 AM
Odd output of 'top' philforrest Linux - General 1 07-20-2004 12:05 AM


All times are GMT -5. The time now is 08:39 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration