У меня есть следующая команда:
$ snmpnetstat -v2c -c public -Cs -Cp udp 10.10.0.32
с выводом терминала:
udp:
198 total datagrams received
65 datagrams to invalid port
0 datagrams dropped due to errors
265 output datagram requests
Я хочу написать скрипт bash, который возвращает следующее:
желаемый вывод скрипта bash:
Received Datagrams: 198
Invalid port:65
Dropped datagrams: 0
Datagram requests: 256
Я начал с:
#!/bin/bash
rs="$(snmpnetstat -v2c -c public -Cs -Cp udp 10.10.0.32)"
ReceivedDatagrams=$(echo $rs | cut -d"/" -f1)
InvalidPort=$(echo $rs | cut -d"/" -f2)
DroppedDatagrams=$(echo $rs | cut -d"/" -f3)
DatagramRequests=$(echo $rs | cut -d"/" -f4)
echo "Received Datagrams:$ReceivedDatagrams Invalid port:$InvalidPort Dropped datagrams:$DroppedDatagrams Datagram requests:$DatagramRequests"
Вывод:
zsz@bme-ib112-05:~/bash_scripts$ ./script.sh
Received Datagrams:udp: 242 total datagrams received 37 datagrams to invalid port 0 datagrams dropped due to errors 638 output datagram requests Invalid port:udp: 242 total datagrams received 37 datagrams to invalid port 0 datagrams dropped due to errors 638 output datagram requests Dropped datagrams:udp: 242 total datagrams received 37 datagrams to invalid port 0 datagrams dropped due to errors 638 output datagram requests Datagram requests:udp: 242 total datagrams received 37 datagrams to invalid port 0 datagrams dropped due to errors 638 output datagram requests
Выходные значения повторяются снова и снова, а не так, как я хотел.