![需要重新启动cups才能连接网络打印机](https://linux22.com/image/104490/%E9%9C%80%E8%A6%81%E9%87%8D%E6%96%B0%E5%90%AF%E5%8A%A8cups%E6%89%8D%E8%83%BD%E8%BF%9E%E6%8E%A5%E7%BD%91%E7%BB%9C%E6%89%93%E5%8D%B0%E6%9C%BA.png)
每隔一段时间(不一定是从挂起或启动恢复后)我必须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