I have some troubles with this script
#! /bin/sh
case $1 in
upssms)
logger -t upssched-cmd "The UPS has been gone for 30 secs. Warn by sms..."
/bin/echo "Power failed. System will hibernate soon..." | /usr/bin/curl "https://service.com/sendmsg=Failure!"
;;
upsgone)
logger -t upssched-cmd "The UPS has been gone for 2 and a half minutes. Hibernating..."
#/usr/sbin/hibernate # direct call to hibernate is not allowed by non-root
/usr/sbin/upsmon -c fsd # call a shutdown in NUT instead
;;
ups-back-on-power)
logger -t upssched-cmd "The UPS power has been restored."
/bin/echo "Power restored." | /usr/bin/curl "https://service.com/sendmsg=Back!"
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
and I can't figure out where the bug is since I don't get notification. Help!
Bash gets super touchy about ! marks within double-quotes. I modified the URLS to use the URL Encoded version of the exclamation. Hexidecimal code 21 per ASCII Tables. http://www.asciitable.com/
#! /bin/sh
# If your heart is set on using exclamations
# Use this syntax - "sendmsg=Failure"'!'
case $1 in
upssms)
logger -t upssched-cmd "The UPS has been gone for 30 secs. Warn by sms..."
/bin/echo "Power failed. System will hibernate soon..." | /usr/bin/curl "https://service.com/sendmsg=Failure%21"
;;
upsgone)
logger -t upssched-cmd "The UPS has been gone for 2 and a half minutes. Hibernating..."
#/usr/sbin/hibernate # direct call to hibernate is not allowed by non-root
/usr/sbin/upsmon -c fsd # call a shutdown in NUT instead
;;
ups-back-on-power)
logger -t upssched-cmd "The UPS power has been restored."
/bin/echo "Power restored." | /usr/bin/curl "https://service.com/sendmsg=Back%21"
;;
*)
logger -t upssched-cmd "Unrecognized command: $1"
;;
esac
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.