Answer the question
In order to leave comments, you need to log in
What is the problem with output?
Hello. I can't figure out what I'm doing wrong. I need to output data in this form:
Nickname IP
for((integer = 1; integer <= ${user_total}; integer++))
do
user_nick=$(occtl --json show users | grep 'Username' | awk -F ":" '{print $2}' | grep -E -o "([A-Z,a-z,0-9]{1,10})" | grep -v ',')
user_IP=$(occtl --json show users | grep 'Remote IP' | awk -F ":" '{print $2}' | grep -oE '\b[0-9]{1,3}(\.[0-9]{1,3}){3}\b')
user_list_all=${user_list_all}"Пользователь: "${user_nick}" IP: "${user_IP}""
done
echo -e "${user_list_all}"
Answer the question
In order to leave comments, you need to log in
For greater clarity, it would be worthwhile to take an example of the command output
occtl --json show users
so that the responders do not have to set up a VPN server and connect test users.
It is immediately clear that you are requesting the result in json format, and then parsing it with grapples and awk, which is extremely pointless and merciless. Why not use jq for this purpose instead of trying to hammer a screw.
The problem you cited is related to the fact that, probably, the output in the form of json occurs without a guarantee of the order of the keys, and your way of getting data from it is very barbaric.
And the problems in this approach will not be limited to this, because the list of users can change between iterations and even between getting the name and ip.
It would be necessary to get all the raw data once, and then pull out the right one from them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question