1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Solved: Counter-reading batch

Discussion in 'Software Development' started by TacticalSniper, Apr 12, 2010.

Thread Status:
Not open for further replies.
Advertisement
  1. TacticalSniper

    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.
     
  2. TheOutcaste

    TheOutcaste

    Joined:
    Aug 7, 2007
    Messages:
    9,028
    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
     
  3. TacticalSniper

    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!
     
  4. Squashman

    Squashman 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.
     
  5. TacticalSniper

    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.
     
  6. Sponsor

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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/916319

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice