how to build a ping and log dos script win 7

January 11, 2012 at 08:42:38
Specs: Windows 7
Hi,

I need to script a batch file in CMD on Win 7 to ping a server and then log & timestamp the results of the ping. Have found other scripts but when I implement I either end up with a '1' appearing before the '>>' for appending to the log file, or I get a message stating "The process cannot access the file because it is being used by another process".

Any help would be greatly appreciated

Barry


See More: how to build a ping and log dos script win 7

Report •

#1
January 11, 2012 at 09:32:06
Try this one...

@echo off
date /T >> pinglog.log
ping %1 >> pinglog.log


Report •

#2
January 12, 2012 at 03:21:02
Hi new to this, can you explain how to implement or set value for % ?

I did try the above, I saved it as ping.bat on the desktop and ran it however I got an error

"The process cannot access the file because it is being used by another process."

It successfully creates the pinglog.log file which only contains

"12-Jan-12"

Any further help with this would be great.

Thanks


Report •

#3
January 12, 2012 at 11:11:24
Sorry about that Barryt06, I should have been more clear about those numeric variables. Whenever you see them, %1 %2 %3, those are arguments that you specify when you run the file. In this case, %1 is the host you want to ping. So when you enter the command to start the batch file, it should look like this:

ping.bat hostname


Report •

Related Solutions

#4
January 13, 2012 at 01:30:36
Thank you very much jowah, I think I understand, you mean if launching through CMD you would type ping.bat hostname and the hostname would pass to the %1 variable?

I have tried this, i.e. in CMD

ping.bat www.website.com

However I still get the error:

"The process cannot access the file because it is being used by another process."

Also:

I need to time this to run every 30 mins or so, so the way I was planning to accomplish this was using scheduled tasks to run the ping.bat file every 30 mins.

Do you know if it is possible to still pass the hostname to %1 with scheduled tasks?

Sorry about this, I haven't used CMD in a long time and when I did, I was never great at it.

Barry


Report •

Ask Question