每隔一段时间(不一定是从挂起或启动恢复后)我必须sudo /etc/init.d/cups restart
再次查看网络打印机。有没有办法绕过这个过程,或者在 Lubuntu 16.04 下自动化它的最佳方法是什么?
答案1
对于基于 Linux 的 shell 脚本,您可以尝试按如下方式安排脚本:
crontab 条目:
*/5 * * * * sh /scripts/cups_recursive_checking.sh
#/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 [email protected]' [email protected] \
-s "CUPS Notification" < /scripts/cups.txt
fi
###END OF THE SCRIPT###
例子 : 在 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