Skip to main content

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 in the arrays for the last value of $i

$i--;

# Now having collected the data from printcap we dump the stanza for printers.conf
while ( $j <= $i ){
 print "\n";
 print "Info\n";
 print "Location\n";
 print "DeviceURI lpd://$Server[$j].my.company.internal.domain.com/$PrintQueue[$j]\n";
 print "State Idle\n";
 print "Accepting Yes\n";
 print "JobSheets none none\n";
 print "QuotaPeriod 0\n";
 print "PageLimit 0\n";
 print "KLimit 0\n";
 print "\n";
 $j++;
}


-Adam

Comments

Post a Comment

Popular posts from this blog

How to fix this ssh error from a Cisco switch: ssh_rsa_verify: RSA modulus too small: 512 < minimum 768 bits

Problem ssh user@cisco_switch returns: ssh_rsa_verify: RSA modulus too small: 512 < minimum 768 bits key_verify failed for server_host_key Solution The modulus of the ssh RSA key pair on the switch is too small. If you have access, generate a new key pair on the switch with a larger modulus. Procedure Login with ssh protocol version 1 ( ssh space dash one ): ssh -1 user@cisco_switch (On the switch): enable (On the switch): Authenticate to "Privileged Exec Mode" mode on the switch. (On the switch): conf t (On the switch): crypto key generate rsa general-keys modulus 1024 (On the switch): Press enter to accept that the current key pair for the switch will be replaced. You now should be able to log into the switch with ssh protocol version 2.

How do I dual-boot Ubuntu 18.04 on a 2011 Mac Mini?

Machine Specs: Mac Mini (Mid 2011), Macmini5,2 Core i7 16 GB RAM (2x8 GB) AMD Radeon HD 6630M 256MB 27-inch Apple Thunderbolt Display 512 GB SSD Running macOS 10.13 High Sierra Caution: This process can result in data loss. If you have personal data on the Mac Mini before starting, back it up first. Twice! (One is none. Two is one. ~ U.S. Navy Seal saying).  Also, mistyping in the parts of this process may brick your Mac Mini. You have been warned. If in doubt, stop working and do research on Google until you understand what's going on in the step. If you find an error, please leave a comment. I will update. Note: This is process I figured out in lieu of booting the Ubuntu install with EFI via refind. Via the refind boot method, I would constantly get: 10:39:07 kernel: Couldn't get size: 0x800000000000000e 10:39:07 kernel: MODSIGN: Couldn't get UEFI db list 10:39:07 kernel: Couldn't get size: 0x800000000000000e The error seems to be relate

Fixing SSH connection problems in EGit in Eclipse

Note: I posted a version of this on Stack Overflow. Errors can occur when there is an underlying SSH authentication issue, like having the wrong public key on the git remote server or if the git remote server changed its SSH host key. Often the an SSH error will appear as: " Invalid remote: origin: Invalid remote: origin" Eclipse will use the .ssh directory you specify in Preferences -> General -> Network Connections -> SSH2 for its ssh configuration. Set it "{your default user directory}.ssh\" . To fix things, first you need to determine which ssh client you are using for Git. This is stored in the GIT_SSH environmental variable. Right-click on "Computer" (Windows 7), then choose Properties -> Advanced System Settings -> Environment Variables. If GIT_SSH contains a path to plink.exe, you are using the PuTTY stack. To get your public key, open PuTTYgen.exe and then load your private key file (*.ppk). The listed public key sho