Dev/기타
shell script로 구현하는 URL 상태 체크
newtype
2013. 11. 14. 16:29
Shell Script로 특정 URL의 상태를 체크하고자 합니다.
curl을 이용하면 간단 하네요.
curl은 결과를 exit code로 리턴 합니다.
exit codes list는 아래 man page를 참고하세요.
( http://curl.haxx.se/docs/manpage.html )
#! /usr/bin/sh
function check {
if [ $? -ne 0 ] ; then
echo "Error occurred getting URL $1:"
if [ $? -eq 6 ]; then
echo "Unable to resolve host"
fi
if [$? -eq 7 ]; then
echo "Unable to connect to host"
fi
exit 1
fi
}
curl -s -o "/dev/null" $1
check;
[ 출처 ]
반응형