add all network printers found via snmp call
I have a task to add all the network printers found on a local LAN segment on our Linux thin clients. I think I have some of the fundamentals down on how to find them via an snmp discovery, and I now some of the basics on how to add a cups printer (not in the code snippit), but the thing I'm stuck on is how to get the information split up into usable chunks.
Here is the basic code for the discovery: Code:
#!/bin/bash network socket://192.168.24.12 "Canon iR5070 35.05" "Canon iR5070 35.05" "" "description x" network socket://192.168.24.13 "Canon iR3570 35.06" "Canon iR3570 35.06" "" "description y" network socket://192.168.24.15 "Canon iR5070 37.01" "Canon iR5070 37.01" "" "" network socket://192.168.24.16 "Canon iR5070 37.01" "Canon iR5070 37.01" "" "Location x" So here is my question. How to do I split each line into the usable chucks. I'm thinking a regular expression, but to be honest, sometimes those blow my mind on how to set them up. I'm thinking I (for example) in line: network socket://192.168.24.12 "Canon iR5070 35.05" "Canon iR5070 35.05" "" "description x" ...I would need to remove the "network socket://192.168.24.12" so I'm just left with: "Canon iR5070 35.05" "Canon iR5070 35.05" "" "description x" ...then split each field into variables so I can use them in the lpadmin command later: var1="Canon iR5070 35.05" var2="Canon iR5070 35.05" var3="" var4="description x" Anyone know how I would accomplish this? |
Mad props on the discovery. ;) You are wise.
RE is the way to "go", but I lack the .fu myself, however, one possible solution could be... Code:
cut -d\" -f2 x Code:
cut -d\" -f2- x where x has ... Code:
network socket://192.168.24.12 "Canon iR5070 35.05" "Canon iR5070 35.05" "" "description x" |
Thanks Habitual. For what it's worth, this is what I have so far. I asked a co-worker and this was the method he suggested. That said, I have a bunch more work to figure out on dealing with cups drivers. I'll post the final code when I'm done.
Code:
#!/bin/bash |
Quote:
|
getting very warm
Well the script is getting closer. Haven't decided on if I want to flat out install all the drivers we will need on the device, or figure out a creative way to do that.
Only thing I haven't quite figured out is how to deal with printers that come back with snmp names like "Lexmark Lexmark E360dn", when if I was to query for just "Lexmark E360dn", I find a driver. I REEEEELY don't want to have to come up with a case statement looking for known stupid returned names. You can add your own log_msg log sub. We actually have an "include" that is sort of proprietary. Code:
#!/bin/bash |
final
Just got done putting some finishing touches on this. I had to run another script to sort of gather an inventory at all our sites so I knew how to deal with some of the odd-ball returns I was getting from the snmp call. Hope this helps someone else!
Code:
#!/bin/bash |
All times are GMT -5. The time now is 07:28 AM. |