Update the printers comments as per the file

Hi,

I have 80 printers in my Organization.All are network printers which are configured in 2 print servers.
I want a way that i can update the printer comments with the serial no of the printer.Any way that a script can take the serial no of each printer and update the Comments tab..Or a way that i have a txt file with the printer names and serial no's can the script update it.

Ex:
Printername       Serial no

Regards
Sharath
LVL 11
bsharathAsked:
Who is Participating?
 
ozoConnect With a Mentor Commented:
change txt file which has the printernames and serial no's to the name of the txt file which has the printernames and serial no's
and change printer comments to the names of the files who's comments you want to change

If you prefer an awk script
awk 'BEGIN{while( getline < "txt" ){ split($0,g,":"); s[g[1]]=g[2]; }; while( getline < "comments" ){ if( s[$1] ){ $2=s[$1]; } print;  } }'
0
 
ozoCommented:
where would the script find the serial numbers with which to do the updates?
0
 
bsharathAuthor Commented:
Hi,

I have a txt file which has the printernames and serial no's
Ex:
Printername:Serialno
0
 
ozoCommented:
#!/usr/bin/perl
open F,"<txt file which has the printernames and serial no's" or die $!;
my %S=map/(\w+):(.+)/,<F>;
close F;
{local @ARGV=qw(printer comments); local $^I=".bak";
  while( <> ){
     s/(\w+)(\s*)(.*)/$1.$2.($S{$1}||$3)/e;
     print;
  }
}
0
 
bsharathAuthor Commented:
How do i run this...Is it a perl script...Inever have run a perl script.Can you explain please
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.