Skip to content

Instantly share code, notes, and snippets.

@FennyFatal
Last active August 29, 2015 14:08
Show Gist options
  • Save FennyFatal/3224a6cc9346548d587d to your computer and use it in GitHub Desktop.
Save FennyFatal/3224a6cc9346548d587d to your computer and use it in GitHub Desktop.
#!/bin/bash
fail="t"
command="$@"
echo ""
while [[ "$fail" == "t" && "$command" != "q" ]]
do
printers=" "
failed=" "
for printer in $command
do
ptest=$(lpstat -p $printer 2>&1 >/dev/null)
if [[ "$ptest" != *Invalid* ]]
then
fail="f"
printers="$printer $printers "
else
failed="$printer $failed"
fi
done
if [[ "$failed" != " " ]]
then
echo "The following printer names are invalid: $failed"
echo ""
fi
if [[ "$fail" == "t" ]]
then
printersin=""
echo "Please list the printers you would like to manage, or enter 'q' to quit."
read -p ">" command
fi
done
if [[ "$command" != "q" ]]
then
echo "Currently managing: $printers"
echo ""
echo "Enter 's' to view status, 'c' to clear all jobs, 'e' to enable printers, 'd' to disable printers, or 'q' to quit."
fi
while [[ "$command" != "q" ]]
do
read -p ">" command
case $command in
c)
for printer in $printers
do
echo Clearing $printer
lprm -P $printer -
done
;;
e)
for printer in $printers
do
echo Enabling $printer
cupsenable $printer
done
;;
d)
for printer in $printers
do
echo Disabling $printer
cupsdisable $printer
done
;;
s)
for printer in $printers
do
lpstat -p $printer -o $printer
done
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment