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 ...
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.
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.
i'm trying to make this script to work on both Linux and SunOS, is there a different command that i could use in place of ps that would do the same thing? Like you said SunOS won't allow ps gu...