I get list of PIDs in my bash scripts (Java processes) and have to analyze their command-line arguments to determine which instance of server each PID corresponds to.
At the moment I do it that way using sed/cut:
PARGS=$(pargs -l $PID)
PARGS_ARR=($PARGS)
NODE='UNKNOWN'
for ARG in ${PARGS_ARR[@]}
do
# trim single quotes
ARG=$(echo $ARG | sed "s/'//g")
# split by equals sign
ARGL=$(echo $ARG | cut -f1 -d=)
ARGR=$(echo $ARG | cut -f2 -d=)
if [ "$ARGL" == "-DnodeId" ]; then
NODE=$ARGR
fi
done
But it works EXTREMELLY SLOW due to large number of command-line parameters (about 20-30 per each PID).
Is there a way to somehow parse command-line parameters and get key=>value parse with a single command?
awk: syntax error near line 1 awk: illegal statement near line 1
Can't rigure out why.
– user1065145 Mar 21 '14 at 12:42(g)awk
4.0.1 running on Debian. – Joseph R. Mar 21 '14 at 12:46