How do I get a field out of a ps cmd result that will always fall after a known string?
On each server there is one to n port listeners running.
Each port listener has a name assigned by the local admin. (eg. LIST_1, LIST_BILL, etc)
Each process is running under the same binary. (eg. X)
I am looking for an active process(s) on a server and when I find it the next field will be an assigned port listener name.
Example of the ps result
billy 6758 1 0 Feb 8 ? 4:49 /app/opt/org/product/ver1/bin/X LIST_JOHN -inherit
The ps result line varies in number of return fields.
Here is my program code line that is not working correctly.
ProcessName=$(ps -ef|grep -i X|grep -v grep|awk 'match($0,"X " {print substr($0,RSTART+RLENGTH)}')
RESULTS
" {print substr($0,RSTART+RLENGTH
LIST_JOHN -inherit
OR sometime the lines are reversed.
I am not sure if I am using RSTART and RLENGTH correctly. I am using RSTART+RLENGTH because this is not always true => awk '{if(NF != 11) print $9; else print $10;}'
Any ideas will greatly help
On each server there is one to n port listeners running.
Each port listener has a name assigned by the local admin. (eg. LIST_1, LIST_BILL, etc)
Each process is running under the same binary. (eg. X)
I am looking for an active process(s) on a server and when I find it the next field will be an assigned port listener name.
Example of the ps result
billy 6758 1 0 Feb 8 ? 4:49 /app/opt/org/product/ver1/bin/X LIST_JOHN -inherit
The ps result line varies in number of return fields.
Here is my program code line that is not working correctly.
ProcessName=$(ps -ef|grep -i X|grep -v grep|awk 'match($0,"X " {print substr($0,RSTART+RLENGTH)}')
RESULTS
" {print substr($0,RSTART+RLENGTH
LIST_JOHN -inherit
OR sometime the lines are reversed.
I am not sure if I am using RSTART and RLENGTH correctly. I am using RSTART+RLENGTH because this is not always true => awk '{if(NF != 11) print $9; else print $10;}'
Any ideas will greatly help