我做一个脚本定期监测到端口的连接(在这种情况下,80)。
我写这篇简短的脚本。
echo '=================================';a=`sudo lsof -i :80`;echo $a | awk '{print $1," ",$2," ",$3," ",$8}'; b=`echo $a | wc -l`; b=$(($b - 1));echo Total SSH Connections: $b;echo '================================='
输出是:
=================================
COMMAND PID USER NODE
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
acwebseca 90 root TCP
Total SSH Connections: 19
=================================
但是,当尝试使用监视命令时,它抛出了我的错误,我无法看到的输出,当我取消命令我看到这样的错误:
sh: PID: command not found
sh: -c: line 1: syntax error near unexpected token `('
sh: -c: line 1: `acwebseca 90 root 37u IPv4 0x81ae738f91e7bed9 0t0 TCP 192.168.0.11:49915->108.160.163.33:http (ESTABLISHED)'
我怎样才能解决这个问题。
watch -n 2 "echo '=================================';a=`sudo lsof -i :80`;echo $a | awk '{print $1," ",$2," ",$3," ",$8}'; b=`echo $a | wc -l`; b=$(($b - 1));echo Total SSH Connections: $b;echo '================================='"