Hello, I am looking for help on adding loop statements to my current working bash script. What the script does is look for a particular printer by protocol and remove it. What I would love to do is remove ALL printers found with that protocol. I have played with a few examples of 'while' and 'until' loop statements but can't seem to get it right. Code is a bit messy and I'm sure it can be simplified.
Code:
printer1=$(lpstat -s | grep '10.18.28.17' | awk -F'/' '{print $3}')
printer01=$(lpstat -s | grep 'smb://sea22233.internal.company.com/SEC2-Canon' | awk -F'/' '{print $3}')
if [ -z $printer1 ]; then
:
else
remove_printer1=$(lpstat -s | grep '10.18.28.17' | awk -F ' ' '{print $3}' | sed s/://g)
lpadmin -x $remove_printer1
remove_printer2=$(lpstat -s | grep 'lpd://10.18.28.17/' | awk -F ' ' '{print $3}' | sed s/://g)
lpadmin -x $remove_printer2
remove_printer3=$(lpstat -s | grep 'ipp://10.18.28.17/' | awk -F ' ' '{print $3}' | sed s/://g)
lpadmin -x $remove_printer3
if [ -z $printer01 ]; then
:
else4
remove_printer=$(lpstat -s | grep 'smb://sea22233.internal.company.com/SEC2-Canon' | awk -F ' ' '{print $3}' | sed s/://g)
lpadmin -x $remove_printer4
fi
Last edited by a moderator: