Last active
February 18, 2016 23:45
-
-
Save FredCox3/73dfbba489c2d5a832d2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Printer Destroyer Script | |
# Freddie Cox - January 2016 for Knox County Schools | |
# | |
# Use Paramter 4 on JSS Script to remove a specific IP address. | |
echo "[INFO] printer_destroyer script. Parameter 4 Value: ${4}" | |
# Get full list of printers & search for socket connection using IP | |
printer=$(lpstat -s | grep 'socket.*'${4} | awk -F'/' '{print $3}') | |
# If Printer variable is empty, then don't act. Else. Try to remove | |
if [ -z $printer ]; then | |
# I didn't find anything. End it here. | |
echo "[INFO] Printer Not Found. No removal necessary." | |
else | |
# Printer IP was found. Lets try to remove it. | |
echo "[INFO] $printer Printer Found. Attempting to remove." | |
# Use lpstat command to find that printer again and get the name, | |
# then clean up the string by removing the trailing colon. | |
# After that, use the lpadmin -x command to remove the printer. | |
remove_printer=$(lpstat -s | grep 'socket.*'${4} | awk -F ' ' '{print $3}' | sed s/://g) | |
lpadmin -x $remove_printer | |
# Check if what we did actually worked. | |
printer_check=$(lpstat -s | grep 'socket.*'${4} | awk -F'/' '{print $3}') | |
if [ -z $printer_check ]; then | |
echo "[INFO] Success! Old Printer Removed." | |
else | |
echo "[ERROR] Something went wrong. Likly two printers with 1 IP. Otherwise, I'm all out of ideas" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment