Solved: Counter-reading batch

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

TacticalSniper

Thread Starter
Joined
Sep 21, 2009
Messages
261
Hey all,

I am somewhat of a sysadmin for an organization. We've got about 25 network connected printers. As those are leased from an outsourced company, we have to provide them with print counters each month. Now, I am able to get the counters through SNMPwalk (thanks to HP support forums). However, now I need to automate it even further.

What I am attempting to do is for the batch script to read another file (say, a CSV) with three entries for each machine - IP address, printer model and a printer asset number. When the batch tells SNMPwalk to request counter, I >> output to a log file. However, in this case the log file only shows the counter, without even a corresponding IP.

So, I am trying to set up a batch that would eventually give this output:

Counter for %IP%, %PrinterModel%, %MachineNumber%:
%Counter%
.

I am having problem making the batch read from another file (as - well - I do not know how).

Any ideas? I could obviously make the entries manually within the batch, but it's so inelegant it makes me cry.

TIA.
 
Joined
Aug 7, 2007
Messages
9,028
Counter for %IP%, %PrinterModel%, %MachineNumber%:
%Counter%
.
The forum shows the above as two lines, I'm assuming it's really just one:
Code:
[I]Counter for %IP%, %PrinterModel%, %MachineNumber%:%Counter%[/I]
If the SMNPWalk command is this
SNMPWalk %IP%
Then this should work:
Code:
@Echo Off
Set _PrinterList=C:\Scripts\PrinterList.csv
Set _OFile=C:\Scripts\Printer.log
For /F "Usebackq Tokens=1-3 Delims=," %%I In ("%_PrinterList%") Do (
For /F "Tokens=* Delims=" %%A In ('[COLOR=Red]SMNPWalk %%I[/COLOR]') Do (
>>"%_OFile%" Echo.Counter for %%I, %%J, %%K:%%A
))
If the command is different, replace the part in red with the correct command, using %%A where you specify the IP address
 

TacticalSniper

Thread Starter
Joined
Sep 21, 2009
Messages
261
Thanks a lot mate. As stupid as it is, I eventually wrote everything manually, as eventually it required more complex coding that this, and I didn't want to bother you (some of the printers are color printers, and for those I need three counters basically - total, BW and color).

I will keep your code though, seems to me it's very useful.

Thanks!
 

Squashman

Retired Trusted Advisor
Joined
Apr 4, 2003
Messages
19,786
I have never seen TheOutcaste back down from a challenge. I don't think he likes to concede defeat. If he can't do it in batch he will try VBscript. If he can't do it in that he may jump to the new PowerShell.
 

TacticalSniper

Thread Starter
Joined
Sep 21, 2009
Messages
261
lol He's good. And I also enjoy challenges. I don't want to bother people without need.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top