Bash generic "ps aux" process by strict name -
i'm trying have ps aux command listing real ssh-agent process. i've noticed on distros, have unwanted process showing up, command colors , such. need because need ensure real ssh-agent process running in script (don't bother, have loop it...).
so figured out need use in test routine:
#!/bin/bash ps aux | grep ssh-agent | grep -v grep | awk '{print $12}'
my question is: awk $12 work on unix/linux env using bash bash versions?
also, if remove "grep -v grep" , this:
ps aux | grep ssh-agent | awk '{print $12}'
output is:
ssh-agent ssh-agent
now:
ps aux | grep ssh-agent
output is:
foo 18153478 0.0 0.0 536 844 - apr 25 0:00 ssh-agent foo 31260886 0.0 0.0 252 264 pts/0 22:38:41 0:00 grep ssh-agent
that means, space between "grep ssh-agent" interpreted delimiter awk command. aynthing possible overcome that? tried using tab delimiter that's not it. seems delimiter of command simple "space" characters. possible enforce tab delimiters "ps" command output?
any idea?
first $12 tied how many fields ps outputs. has nothing bash.
grep -v grep
way remove grep process leave in;
now not if last field field 12 or what, i'm not quite certain
ps aux | grep ssh-agent | grep -v grep | awk '{ print $nf }'
assuming looking see ssh-agent (and has no command-line parameters)
here quick , dirty spit out pid , complete command-line
ps aux | grep ssh-agent | grep -v grep | awk '{ print $1 " "; (k = 12; k < nf; k++ ) { printf "%s", k; } printf "\n"; }'
nf number of fields in awk $nf last field.
see if works you. there cleaner ways of doing though
Comments
Post a Comment