Skip to main content

Posts

Showing posts from April, 2009

Convert lpd printcap to CUPS printers.conf - Rough draft.

It's perl, rather than bash. Some things need a bit more oomph. #!/usr/local/bin/perl -w use strict; my $Printcap = "/hub/share/etc/printcap"; my($a,$b,@Server,$c,@PrintQueue,); my $i = 0; my $j = 0; open (PRINTCAP, "$Printcap") or die "can't open input file"; #Run through the printcap recording the queue and the server in separate arrays. The separate arrays allow us to recall the data #later asynchronously. This looks like it could have been accomplished with a associative array, but there is no unique index, #since two print queues on separate servers can have the same name as far as I know - Adam while () { if ( /^\n$/ ) { $i++; } if ( /:lp\=:/ ) { ($a,$b,$Server[$i]) = split(/=/,$_); chomp $Server[$i]; $Server[$i] =~ s/(\:|\\)//g; } if ( /:rp\=/ ) { ($c, $PrintQueue[$i]) = split(/=/,$_); $PrintQueue[$i] =~ s/(\:|\\)//g; chomp $PrintQueue[$i]; } } # printcap ends on a new line so there will be no elements i