Skip to content

Instantly share code, notes, and snippets.

@brettfreer
Created May 23, 2016 08:32
Show Gist options
  • Save brettfreer/089644888c96b5b9a71762225ddc35e9 to your computer and use it in GitHub Desktop.
Save brettfreer/089644888c96b5b9a71762225ddc35e9 to your computer and use it in GitHub Desktop.
Linux bash script to attempt restarting specifed cups print queues
#!/bin/sh
# restart print queues
process()
{
host=$1 queue=$2
ping -c 1 ${host} 2>&1 >/dev/null
status=$?
if [ $status -eq 0 ]
then
down=`lpq -P${queue} | grep "is not ready" | wc -l`
if [ $down -gt 0 ]
then
echo "Restarting queue ${queue}" #| mail -s "print queue" nobody
/usr/sbin/cupsenable ${queue}
fi
fi
}
main()
{
process printer1.domain.com printer1
process printer2.domain.com printer2
... etc
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment