
서로 다른 두 컴퓨터 간의 연결이 끊어질 때마다 경고를 보내려고 합니다.
기본적으로 PC N°4에서 PC N°5의 포트 6031로 연결이 설정되었는지 PC N°2에서 확인해야 합니다.
PC N°2에는 우분투 서버 16.04, 4, 5, Windows Server 2012가 있습니다.
실제로 연결은 볼 수 있지만 경고를 보낼 수는 없습니다.
저는 현재 이 작은 스크립트를 사용하고 있습니다.
alerta=$(sshpass -p 'password' ssh [email protected] netstat -na | grep "6031")
if [[ $? != 0 ]]; then
(Here goes a code that sends a SMS to my phone saying everything is ok)
else [[ $alerta ]]; then
(Here goes a code that sends a SMS to my phone saying something is not ok)
fi
이것은 명령줄에서 명령을 실행할 때의 출력입니다.
user2@pc2:~$ sshpass -p 'password' ssh [email protected] netstat -na | grep "6031"
TCP 10.8.0.4:54961 10.8.0.5:6031 ESTABLISHED
cra@atlas:~$
작동하지만 crontab을 사용하면 "오류" 메시지만 보냅니다.
이 명령은 루트 및 사용자 계정 모두에서 작동하지만 cron에서 작동시키려고 하면 실패합니다.
미리 감사드립니다.