小智 2
对于基于 Linux 的 shell 脚本,您可以尝试按如下方式安排脚本:
crontab 条目:
*/5 * * * * sh /scripts/cups_recursive_checking.sh
Run Code Online (Sandbox Code Playgroud)
#/bin/sh
HOST='server-name'
/etc/init.d/cups status>/scripts/cups.txt
if grep "cupsd (pid " /scripts/cups.txt
then
echo "cups is already running"
exit
else
/etc/init.d/cups restart
echo "cups just now started in server-name"
############# For mail Notification whenever cups gets restart follow below line according to your email ##########
mutt -e "my_hdr Content-Type: text/html" -e 'set realname=Notification' \
-e 'set from=notification@your-email.com' user@your-email.com \
-s "CUPS Notification" < /scripts/cups.txt
fi
###END OF THE SCRIPT###
Run Code Online (Sandbox Code Playgroud)
示例: 在 Linux 中重启 cups 后检查打印机
lpstat -a
clientPrinter accepting requests since Sat 13 Jul 2019 10:07:01 AM IST
dmx accepting requests since Sat 13 Jul 2019 03:55:05 PM IST
HP_LaserJet_400_M401dw accepting requests since Sat 13 Jul 2019 03:05:06 PM IST
Run Code Online (Sandbox Code Playgroud)