#!/bin/bash
me="$(basename "$0")";running=$(ps h -C "$me"| grep -wv $$| wc -l);[[$running > 1]]&& exit;detect_ip=192.168.1.1
ping_count=1detect_delay=300echo" detect ip:=$detect_ip"echo" detect delay:=$detect_delay sec"ping -c ${ping_count}${detect_ip} > /dev/NULL
if[$? -eq 0]thenecho' AC Power OK !'elseecho" AC Power maybe off, checking again after ${detect_delay} second !" sleep ${detect_delay}#延时秒 ping -c ${ping_count}${detect_ip} > /dev/NULL
if[$? -eq 0]thenecho' AC Power recover, return !'elseecho' AC Power always off, poweroff !' /usr/sbin/poweroff
fifi