Differences

This shows you the differences between two versions of the page.

Link to this comparison view

tech:linux:ping_test [2016/03/03 06:28] (current)
Line 1: Line 1:
 +====== Ping / TCP Ping Test ======
 +Script to check for ping or TCP in a loop and email a limited number of times an error occurs
 +<code bash>
 +#!/bin/bash
 +#
 +TIMEOUT=2
 +PORT=443
 +MAXEMAILS=40
 +IP=xxx.xxx.xxx.xxx
 +EMAIL=someone@example.com
 +SUBJECT=ping_test
 +#
 +errcnt=0
 +while true; do
 +  /​usr/​lib/​nagios/​plugins/​check_tcp -H $IP -p $PORT -t $TIMEOUT
 +  if [ $? -ne 0 ]
 +         then
 +         (( errcnt += 1 ))
 +         if [ $errcnt -lt $MAXEMAILS ]
 +           then
 +           echo "Error Count: $errcnt"​|mailx -s $SUBJECT $EMAIL
 +         else
 +           echo "​Reached max emails"​
 +         fi
 +     date >> ch_${PORT}_${TIMEOUT}.log
 +  fi
 +  sleep 1
 +done
 +</​code>​
  

QR Code
QR Code tech:linux:ping_test (generated for current page)