«   2025/03   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
Recent Posts
Today
Total
03-12 00:02
300x250
관리 메뉴

변군이글루 블로그(Development)

ping check 스크립트 본문

리눅스

ping check 스크립트

변군Dev 2022. 12. 1. 19:47
728x90

ping check 스크립트

vim pingcheck.sh
#!/bin/bash

while true; do
    if ping -c 1 192.168.2.1 >/dev/null; then
        echo "$(date '+%Y-%m-%d %H:%M:%S') : Success" >> tempfile
    else
        echo "$(date '+%Y-%m-%d %H:%M:%S') : Fail" >> tempfile
    fi
    sleep 1
done

이제 위의 코드는 1초마다 192.168.2.1에 대한 ping을 수행하고 결과를 tempfile에 기록하는 스크립트로 사용할 수 있습니다.

chmod +x pingcheck.sh
bash pingcheck.sh &
$ tail -f tempfile
2015-03-27 13:41:35 : Success
2015-03-27 13:41:36 : Success
2015-03-27 13:41:37 : Success
2015-03-27 13:41:38 : Success
2015-03-27 13:41:39 : Success
2015-03-27 13:41:50 : Fail
2015-03-27 13:42:01 : Fail
2015-03-27 13:42:12 : Fail
2015-03-27 13:42:23 : Fail
2015-03-27 13:42:34 : Fail
2015-03-27 13:42:45 : Fail

 

참고URL

- ping, telnet으로 통신(포트) 상태 확인 : https://sangchul.kr/36

 

728x90