Command line...


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Command line...
# 1  
Old 07-09-2004
Command line...

Could someone please explain that this command line does in English please?
Code:
 ps gu|head -n 1;ps gau|egrep -v "CPU|kproc"|grep "${user}"|grep
-v grep|sort +2b -3 -n -r|head -n 10;uptime

everything supposed to be on one(1) line.

i've got different results when running it on Unix and Linux, not sure I understand why.

Thank you much.
# 2  
Old 07-11-2004
Take it command by command: - Looks like you have two seperate command sequences here. The first being the ps -gu | head -n 1 and the second starting from the ps -gau ...

Code:
first set
ps -gu -- gives a display of all processes by group name in a user readble format
head -n 1 --prints the the first line of output piped to it from the first command.
The output of this command is probably (I didnt
run it) just the headings of the ps command.

second set
ps -gau - selection of all processes, in a readable format
egrep -v "CPU|kproc"|grep "${user}"|grep
-v grep|- a search string, basically it ignores and does not output
any lines that have "CPU" or "kproc" in them and outputs all lines
with the value of ${user}. It also ignores any grep string.

sort +2b -3 -n -r|head -n 10 - numeric sort of teh 2nd and third
fields, ignoring blank space and in reverse order.
uptime - prints a display of how long the system has been running

It appears this is just a command set to get all processes for a given user, in a sorted format.

Last edited by google; 07-11-2004 at 12:14 PM..
# 3  
Old 07-13-2004
google, thank you for your translation. However, I'm not sure why when I put in 'root' as $user, no processes started by root came up.
Smilie
# 4  
Old 07-13-2004
I don't understand how that can work.

ps -gu is an illegal option on any server I have seen. If you specify -g or -u, you must suppy a list of groups or users.

Below is the usage doc from ps on our sun system.

usage: ps [ -aAdeflcjLPy ] [ -o format ] [ -t termlist ]
[ -u userlist ] [ -U userlist ] [ -G grouplist ]
[ -p proclist ] [ -g pgrplist ] [ -s sidlist ]

What is the correct string. While I know that this is outside the original scope of the question, I am curious (yellow).
# 5  
Old 07-13-2004
Not sure i understand your question of "what is the correct string".

I'm basically trying to display cpu usage of each process with the option of displaying for a specified user or for all users.
# 6  
Old 07-13-2004
There are many versions of unix and I can believe that this command made sense on one of them.

Look at the internal piece:
ps gau|egrep -v "CPU|kproc"|grep "${user}"|grep -v grep|sort +2b -3 -n -r|head -n 10

First it runs "ps gau".
Then those "grep" commands throw some stuff away.
Then what's left gets sorted.
Then we keep the top 10 lines.

So run "ps gau". No matter what you put in $user, you can only pick and choose from the lines output by the ps command.

On Linux, the g is legal and says to keep process group leaders. And yes the command is legal without a minus sign. On SunOS, I get an error message. It kinda works on HP-UX, but only because "ps xyzzy" works too.
# 7  
Old 07-13-2004
I totally forgot about linux. Thanks for the reply
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How to read the output of a command line by line and pass it as a variable?

Hi, I have some 2000 names in a table like below. Java Oracle/SQL ANSI SQL SQL,DWH,DB DB&Java And by using for loop in my code i am able to get a single word but if there is any special character or space then it is considering as a next line. I have to execute the below queries in... (10 Replies)
Discussion started by: Samah
10 Replies

2. Shell Programming and Scripting

Perl command line option '-n','-p' and multiple files: can it know a file name of a printed line?

I am looking for help in processing of those options: '-n' or '-p' I understand what they do and how to use them. But, I would like to use them with more than one file (and without any shell-loop; loading the 'perl' once.) I did try it and -n works on 2 files. Question is: - is it possible to... (6 Replies)
Discussion started by: alex_5161
6 Replies

3. Shell Programming and Scripting

sed command to replace a line in a file using line number from the output of a pipe.

Sed command to replace a line in a file using line number from the output of a pipe. Is it possible to replace a whole line piped from someother command into a file at paritcular line... here is some basic execution flow.. the line number is 412 lineNo=412 Now i have a line... (1 Reply)
Discussion started by: vivek d r
1 Replies

4. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

5. Shell Programming and Scripting

sed command to grep multiple pattern present in single line and delete that line

here is what i want to achieve.. i have a file with below contents cat fileName blah blah blah . .DROP this REJECT that . --sport 7800 -j REJECT --reject-with icmp-port-unreachable --dport 7800 -j REJECT --reject-with icmp-port-unreachable . . . more blah blah blah --dport 3306... (14 Replies)
Discussion started by: vivek d r
14 Replies

6. Shell Programming and Scripting

sed command to replace a line at a specific line number with some other line

my requirement is, consider a file output cat output blah sdjfhjkd jsdfhjksdh sdfs 23423 sdfsdf sdf"sdfsdf"sdfsdf"""""dsf hellow there this doesnt look good et cetc etc etcetera i want to replace a line of line number 4 ("this doesnt look good") with some other line ... (3 Replies)
Discussion started by: vivek d r
3 Replies

7. Shell Programming and Scripting

Bash - Loading a command's output line by line into an array

I have been trying this a lot of different ways and haven't found too much online. Here's what I've got so far: j=0 declare -a first zero=(`cat $tmpfile`) for i in "${zero}" do command $i >> "${first}" ... (4 Replies)
Discussion started by: Azrael
4 Replies

8. Shell Programming and Scripting

Need help! command working ok when executed in command line, but fails when run inside a script!

Hi everyone, when executing this command in unix: echo "WM7 Fatal Alerts:", $(cat query1.txt) > a.csvIt works fine, but running this command in a shell script gives an error saying that there's a syntax error. here is content of my script: tdbsrvr$ vi hc.sh "hc.sh" 22 lines, 509... (4 Replies)
Discussion started by: 4dirk1
4 Replies

9. Shell Programming and Scripting

Need help in sed command [ printing a pattern + its line no or line no alone ]

Hello friends, Only very recently i started learning sed command...an i found that sed is faster in finding the patterns than some of my scripts that uses grep to check the patten inside a file using line by line search method which is time consuming. The below script... (4 Replies)
Discussion started by: frozensmilz
4 Replies
Login or Register to Ask a Question