需要重启cups才能访问网络打印机

nig*_*d3r 6 cups lubuntu printer autostart

每隔一段时间(不一定在从挂起或启动恢复后)我必须sudo /etc/init.d/cups restart再次查看网络打印机。有没有办法绕过这个过程,或者在 Lubuntu 16.04 下自动化它的最佳方法是什么?

小智 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)