#!/bin/bash #ping_monitor.sh IP_ADDRESS=$1 if [ -n "$IP_ADDRESS" ] ; then while : do PING_OK=`ping -c 1 -W 2 $IP_ADDRESS | grep "time=" ` if [ 0 -eq $? ]; then echo "$PING_OK $TIME_ `date`" >> PING_${IP_ADDRESS}_OK.log else echo "PING $IP_ADDRESS 2seconds TMOUT... `date`" >> PING_${IP_ADDRESS}_TMOUT.log fi sleep 1 done else echo "用法:$0 <IP or 域名>" echo "监控日志请到当前目录下获取" fi
curl 持续监控返回值
#!/bin/bash # #Author:zhangmingda #date:20191021 #use:持续监控https/http连接请求状态 ######################################################### logfile='curl_monitor.log' if [ ! -f ${logfile} ];then touch $logfile fi #日志文件 echo;echo "curl_log result from $1 " |tee -a ${logfile} ######################################################### echo ' DNS_OK: TCP_OK: DATA_START: TOTAL_TIME: http_code:' | tee -a ${logfile} while true ; do tid="$(date '+%F %H:%M:%S')" ; url=$1 ; curl -m 3 -4 -o /dev/null -s -w "curl_tid:${tid} %{time_namelookup} %{time_connect} %{time_starttransfer} %{time_total} code:%{h ttp_code} \n" \ ${url} | tee -a $logfile ; sleep 1; done