killefer762
asked on
How do create a batch file that will ping all the computers from a file then create a new file with only those computers that respond?
I used dsquery to generate a file that contains the names of all computers in the domain. Now i want to create a report that will contain only computers that respond to a ping.
Workstations.txt is a file with all my computers names in it. This command does generate a new file with only the alive machines.
for /f %%a in (workstations.txt) do ping -a -n 1 %%a | find "TTL" >> HostsUp.txt
Here is a sample from the Hostsup.txt file:
Reply from 192.168.1.132: bytes=32 time<1ms TTL=128
Reply from 192.168.1.131: bytes=32 time<1ms TTL=128
Reply from 192.168.1.112: bytes=32 time<1ms TTL=128
Reply from 192.168.1.134: bytes=32 time<1ms TTL=128
What i really want is the HostsUp.txt file to have only the name (or ip) only and get rid of the rest of the info.
I want it to look this way: (it could be the machine name - doesn't matter either way works)
192.168.1.132
192.168.1.131
192.168.1.112
192.168.1.134
Any help is very appreciated !!!
Workstations.txt is a file with all my computers names in it. This command does generate a new file with only the alive machines.
for /f %%a in (workstations.txt) do ping -a -n 1 %%a | find "TTL" >> HostsUp.txt
Here is a sample from the Hostsup.txt file:
Reply from 192.168.1.132: bytes=32 time<1ms TTL=128
Reply from 192.168.1.131: bytes=32 time<1ms TTL=128
Reply from 192.168.1.112: bytes=32 time<1ms TTL=128
Reply from 192.168.1.134: bytes=32 time<1ms TTL=128
What i really want is the HostsUp.txt file to have only the name (or ip) only and get rid of the rest of the info.
I want it to look this way: (it could be the machine name - doesn't matter either way works)
192.168.1.132
192.168.1.131
192.168.1.112
192.168.1.134
Any help is very appreciated !!!
If you insist on having it read ONLY the IP Addresses, then:
FOR /F "tokens=3" %%a in ('find /i "reply" hostsup.txt') do echo %aa
FOR /F "tokens=3" %%a in ('find /i "reply" hostsup.txt') do echo %aa
ASKER
We are getting so close - this is what I get using your command:
C:\Scripts\regperm>FOR /F "tokens=3" %a in ('find /i "reply" hostsup.txt') do echo %aa
C:\Scripts\regperm>echo 192.168.1.132:a
192.168.1.132:a
How can we strip out the :a and only get the ip address?
C:\Scripts\regperm>FOR /F "tokens=3" %a in ('find /i "reply" hostsup.txt') do echo %aa
C:\Scripts\regperm>echo 192.168.1.132:a
192.168.1.132:a
How can we strip out the :a and only get the ip address?
Modify to this:
FOR /F "tokens=3 delims=: " %a in ('find /i "reply" hostsup.txt') do echo %aa
NOTE: THERE MUST be a SPACE after the : in "delims=: "
FOR /F "tokens=3 delims=: " %a in ('find /i "reply" hostsup.txt') do echo %aa
NOTE: THERE MUST be a SPACE after the : in "delims=: "
ASKER
Getting closer - that got rid of the ":" but still has "a" at the end.
C:\Scripts\regperm>FOR /F "tokens=3 delims=: " %a in ('find /i "reply" hostsup.txt') do echo %aa
C:\Scripts\regperm>echo 192.168.1.132a
192.168.1.132a
C:\Scripts\regperm>FOR /F "tokens=3 delims=: " %a in ('find /i "reply" hostsup.txt') do echo %aa
C:\Scripts\regperm>echo 192.168.1.132a
192.168.1.132a
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
You are right - it runs perfectly now :)
Thanks for the help not only was it good but it was fast - much appreciated !!!!!
Thanks for the help not only was it good but it was fast - much appreciated !!!!!
FIND /i "Reply" HostsUp.txt