我对这个剧本有些麻烦
#! /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
我无法弄清楚错误的位置,因为我没有收到通知。 救命啊!
答案 0 :(得分:0)
Bash变得超级敏感!双引号内的标记。我修改了URLS以使用感叹号的URL编码版本。每个ASCII表的十六进制代码21。 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