我有一个 1 班轮,它将 telnet 会话的输出写入文件。
while sleep 5; do sleep 1 | telnet 11.22.33.44 443 | tee -a /var/tmp/test$(date +%Y%m%d).txt && date >> /var/tmp/test$(date +%Y%m%d).txt; done &
我不想看到第一个命令的输出但是想运行这个 1 班轮并显示输出:
awk '!/Trying/{count++}/Trying/{if (count == 4) print "Connected"; else if (count == !NR) print ""; else print "Failed"; count = 0}' test$(date +%Y%m%d).txt
奖金如果!可以在 1 行中同时显示输出,如下所示:
while sleep 5; do sleep 1 | telnet 159.203.162.223 443 | tee -a /var/tmp/test$(date +%Y%m%d).txt && date >> /var/tmp/test$(date +%Y%m%d).txt; done & awk '!/Trying/{count++}/Trying/{if (count == 4) print "Connected"; else if (count == !NR) print ""; else print "Failed"; count = 0}' test$(date +%Y%m%d).txt
Connected
Connected
Connected
Connected
Connected
Connected
Connected
Connected
Connected
Connected
如果可能,您可能需要考虑使用
netcat
(nc
) 而不是尝试解析telnet
输出。例如:--
试试这个更接近你正在寻找的东西