Frank Helk
asked on
Bash - tricky string extraction ....
I'm stuck at a (presumalby simple) problem with bash. I want to extract the info from ntpq -p into separate variables. But I'm stuck at the point where I want to assign the tally code (the asterisk preceeding the first server address) to a variable. ntpq -p returns something like
Any hint how to manage that I get the expected result ?
remote refid st t when poll reach delay offset jitter
==============================================================================
*192.168.20.1 .PZF. 1 u 36 64 377 1.123 -5.097 5.434
192.168.30.2 .INIT. 16 u - 64 0 0.000 0.000 0.000
This is my code by now:
i=192.168.20.1
ntpq -p > $TEMPFILE
TEMPSTRING=$(grep $i $TEMPFILE|gawk '{ print $1 }')
NTP_TALLY=${TEMPSTRING:0:1}
echo NTP_TALLY
I would expect that NTP_TALLY contains a single asterisk, but it contains a list of the files in the current directory - it seems that bash expands it to that. The variable TEMPSTRING contains "*192.168.20.1", as expected.Any hint how to manage that I get the expected result ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER