안녕하세요.리눅스 감시 명령이 스크립트에서 작동하지 않습니다.
포트 (이 경우 80)에 대한 연결을 주기적으로 모니터링하기위한 스크립트를 작성하고 있습니다.
나는이 짧은 스크립트를 작성합니다.
=================================
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
=================================
그러나 시도가 시계 명령을 사용할 때 나에게 오류를 발생 내가 명령을 취소 할 때 나는이 같은 오류가 표시 출력을 볼 수 없습니다 :
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 '================================='
출력은
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 '================================='"
알고 있습니다. 그러나 "하나의"줄로 만들 수있는 방법이 있나. ? – crsuarezf
왜 하시겠습니까? 나의 더 나은 판단에 반하여, 나는 그 대답의 예를 덧붙였다. –
예, 코드의 가독성에 관계없이 작동해야했습니다. – crsuarezf