#!/bin/bash if [[ "$1" =~ ^refresh ]]; then ip=$(echo "$1" | cut -d '/' -f2) body="{\n\"time\": \"$(date +%T)\",\n" body+="\"status\": \"unknown\"\n}\n" cat < status/$ip ret=1 for i in {0..30}; do ping -c 1 -w 5 -t 1 -q "$ip" ret=$? [ $ret -eq 0 ] && break done echo -e "{\n\"time\": \"$(date +%T)\"," > status/$ip if [ $ret -eq 0 ]; then echo -e "\"status\": \"up\"\n}\n" >> status/$ip else echo -e "\"status\": \"down\"\n}\n" >> status/$ip fi exit 0 fi if [[ "$1" =~ ^status ]]; then ip=$(echo "$1" | cut -d '/' -f2) if [ ! -r "status/$ip" ]; then body="{\n\"status\": \"unknown\"\n}\n" else body=$(cat status/$ip) fi cat < /dev/null body="{\"response\": \"ok\"}\n" cat <