[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

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
0
bsharath
Asked:
bsharath
  • 3
  • 2
1 Solution
 
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
 
ozoCommented:
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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now