TechUserCJ
Thread Starter
- Joined
- Apr 20, 2009
- Messages
- 7
Hey all,
I am in charge of searching for files at our clients' firms using a batch file. One issue I run into is that some computers at a firm may be left off, and so the search for the files is unsuccessful. It'd be nice to have a way to check if the relevant computers at a firm are on. As such, I am working on an automated ping batch file that reads IPs from a text file and logs the results to a batch file.
I am not so experienced with writing batch files, but I was able to cobble something together based on some code I saw online. However, it's not working--it logs IP addresses as responding whether or not they actually are. I have reproduced the batch code below. I assume that the problem has something to do with the error level. If someone could take a look and give me some pointers on getting the code to work (and perhaps some insight into why what I have doesn't work), I would greatly appreciate it. Thanks.
I am in charge of searching for files at our clients' firms using a batch file. One issue I run into is that some computers at a firm may be left off, and so the search for the files is unsuccessful. It'd be nice to have a way to check if the relevant computers at a firm are on. As such, I am working on an automated ping batch file that reads IPs from a text file and logs the results to a batch file.
I am not so experienced with writing batch files, but I was able to cobble something together based on some code I saw online. However, it's not working--it logs IP addresses as responding whether or not they actually are. I have reproduced the batch code below. I assume that the problem has something to do with the error level. If someone could take a look and give me some pointers on getting the code to work (and perhaps some insight into why what I have doesn't work), I would greatly appreciate it. Thanks.
Code:
@echo off
Set CompList=complist.txt
Set PingListLog=pinglistlog.txt
If Not Exist "%CompList%" (
Echo Cannot find list of computers called %CompList%
Pause
GoTo :EndOfScript
)
echo Scanning began on %date% at %time% > %PingListLog%
for /f %%i in (%CompList%) do call :ScanLbl %%i
echo Scanning completed on %date% at %time% >> %PingListLog%
GoTo :EndOfScript
:ScanLbl
echo Scanning %1
set attrib=responding
ping -n 1 %1
if errorlevel 1 set attrib = nonresponsive
echo %1 is %attrib% >> %PingListLog%
:EndOfScript