|
Answer» I'm TRYING to find a way to pull info from a .txt (or other file) to assist me in pinging a large number of computers (one at a time). I need to know how to go about this. Do I need to USE IF statements or can I have all the computer names one per line in the .txt file. Syntax is ANOTHER area I'm not sure about in this particular instance.
EXAMPLE:
ping < "C:\Computer List.txt" isn't working for me.
If you need further info to help me with this please reply with your questions and I'll be happy to fill in what I know. ThanksTry using a for statement:
for /f %a in (C:\Computer List.txt) do ping %a
You may run into problems with a file name with embedded spaces. If so just REMOVE the embedded space.
Hope this helps.
Note: the above example is set to run at the command line. In a batch file, use:
for /f %%a in (C:\Computer List.txt) do ping %%aThat's got it! Thanks. I'm only now starting to get into making more use of .bat files. I've been tinkering with them for a while but haven't used them to their full potential mostly because of this issue right here. The next thing I'm going to do with this is strip the IP Address from the "Reply from *.*.*.*" return I get once I ping a machine. You wouldn't happen to know how to do this as well would you? I know the FIND command is used but I only want the IP Address not the entire line. If striping the IP is not possible then the entire line will do. Thanks for the help and I saw your input on Samanathon's issue. I do what I can but sometime an expert is needed.I'm not sure why you need to extract the IP address when you already had it to do the ping. Nevertheless, I'm easy, so you might want to try this:
Code: [Select] for /f %%a in (c:\computerlist.txt) do (ping %%a > ping.txt) for /f "tokens=1-4* delims=: " %%i in ('find "Reply" ping.txt') do echo %%k
PS. Welcome Mental, we can use all the help we can get. Sorry, I'm pinging the machines based on their Workstation Names. I have a list of the names but not their IP's. They are re-leased every 30 days and I'm not the domain admin, just the the Section admin. The "powers that be" limit what we have access to even as a section admin. Love those guys :-/The code I gave you will still work. If you prefer, you can write it as a single piece of code and eliminate the temp file:
Code: [Select] @echo off for /f %%a in (c:\computerlist.txt) do ( ping %%a | for /f "tokens=1-4* delims=: " %%i in ('find "Reply"') do (echo %%k ) )
Yeah, yeah, I know it's *censored* ugly but hey, so is batch language.
|