Thursday, July 27, 2017

# get printers list on unix # hpux script tp extract printers list

UNIX : Shell script to extract printers from servers and email to users

This is a handy script especially if you are working with printers of all kinds running on hundreds of servers that does nothing but print all day and night and you want to troubleshoot/run maintenance/replace cartridges/remove/add those printers

For the purpose of this tutorial, I have renamed the servers and the email recipient list

The output will be in a CSV format emailed to user, and a copy is stored in /var/local/printers

I stored this script in /usr/local/bin/ and named it printer_list.sh script

This script also does a bit of a housekeeping, it removes existing csv file on the server it is run on which is older than 90 days

# Get printer config from all servers

OUT_DIR="/var/local/printers"
OUTPUT="${OUT_DIR}/all_printers_`date +%Y%m%d.%H%M%S`.csv"
HOSTNAMES="hedkandi bluekandi brocadeblue milkyway starrynite abyss " 
MAIL_LIST="brocadeblue@gmail.com hedkandi@gmail.com"
SUBJECT="PRINTERS_FROM_ALL_SERVERS_`date +%Y%m%d.%H%M%S`.csv"

echo "Server  ,Queue name,Device,Remote Device,HP-UX Interface Device,Port  ,IP add from hosts,PING,DNS IP add,Model" > $OUTPUT

for i in $HOSTNAMES
do
ssh $i "sh /usr/local/bin/printer_list.sh" >> $OUTPUT
done

#sort -t "," -k 2,2 -k1,1 $OUTPUT > ${OUTPUT}2
#mv  ${OUTPUT}2 $OUTPUT

# remove printer lists older than 90 days
find $OUT_DIR -name "all_printers*.csv" -mtime +90 -exec rm {} \;

# Mail file to selected people
uuencode $OUTPUT $OUTPUT | mail $MAIL_LIST 

Works on HP UX 11 and later

No comments:

Post a Comment