| | | Member
Join Date: Jan 2009
Posts: 72
| How do a write a simple windows ping script and schedule it? I want to write a simple windows script that allows one pc to ping a host (10.1.1.1) at particular times during the day. How do I go about it?
Last edited by mrblackmamba343; 12-30-2009 at 03:03 PM.
|
| | Login/register to remove this advertisement. | | | Senior Member
Join Date: Dec 2006 Location: Dublin, Ireland
Posts: 335
Certifications: CCNA, CCENT, CWNA, Security+, Network+, A+, MCP, MCSA | Quote:
Originally Posted by mrblackmamba343 I want to write a simple windows script that allows one pc to ping a host (10.1.1.1) at particular times during the day. How do I go about it? | Open notepad.
Type:
ping 10.1.1.1
Save it is ping.bat or whatever.bat.
Use windows task scheduler to schedule the batch file to run.
You'll want the results outputted somewhere though.
Look up windows batch files and windows task scheduler.
__________________
"There are 3 types of people in this world, those who can count and those who can't" www.cullbox.com |
| | | Virtually in the shadows
Join Date: Oct 2008 Location: Peoria, IL
Posts: 140
Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0 | Ping script Going along with ConstantlyLearning I would agree and if you want a written log would add this for example. Name the script serverping.bat and use the scheduled task like was mentioned as it is the easiest way.
ping Server1 >>D:\ServerPing.txt
ping Server2 >>D:\ServerPing.txt
net time >> ServerPing.txt
The >> will append the text file so you have a complete record. The net time will give you a exact time from your DC. It would log the following.
Current time at \\ServerDC1 is 12/30/2009 9:53 AM
The command completed successfully.
__________________
-----------------------------------------------------
The more knowledge one obtains the more there is too accumulate.....
-------------------------------------------------------
|
| | | Member
Join Date: Jan 2009
Posts: 72
| Quote:
Originally Posted by ConstantlyLearning Open notepad.
Type:
ping 10.1.1.1
Save it is ping.bat or whatever.bat.
Use windows task scheduler to schedule the batch file to run.
You'll want the results outputted somewhere though.
Look up windows batch files and windows task scheduler. | I did what you just said but the batch file runs and never stops when I clicked on it. I want a situation where the ping stops after a minute or two. Is that possible? |
| | | Virtually in the shadows
Join Date: Oct 2008 Location: Peoria, IL
Posts: 140
Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0 | Ping script Add the following line to the end of the batch file. Typing exit as the last line will exit the script. Let me know how it goes.
Exit
__________________
-----------------------------------------------------
The more knowledge one obtains the more there is too accumulate.....
-------------------------------------------------------
|
| | | Member
Join Date: Jan 2009
Posts: 72
| Quote:
Originally Posted by pennystrader Add the following line to the end of the batch file. Typing exit as the last line will exit the script. Let me know how it goes.
Exit | my script reads
ping 10.1.1.1
exit
exit still doesn't stop the ping. Is there a way I can let the ping run for only once or twice in the script?
Last edited by mrblackmamba343; 12-30-2009 at 02:59 PM.
|
| | | Virtually in the shadows
Join Date: Oct 2008 Location: Peoria, IL
Posts: 140
Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0 | Ping script What do you mean run once or twice? It will ping all machines once and log it to text and then exit. I guess I am not really sure what you are asking me.
__________________
-----------------------------------------------------
The more knowledge one obtains the more there is too accumulate.....
-------------------------------------------------------
|
| | | Member
Join Date: Jan 2009
Posts: 72
| Quote:
Originally Posted by pennystrader What do you mean run once or twice? It will ping all machines once and log it to text and then exit. I guess I am not really sure what you are asking me. | when I run the current script as it is, it runs multiple ping instances everything scroll by so fast I can't see nothing |
| | | Virtually in the shadows
Join Date: Oct 2008 Location: Peoria, IL
Posts: 140
Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0 | Ping script I understand now. Ok I tested it and it bombed out on me too. I had not tried it yet. Let me mess with it and will post a working code here when I get a chance. it should not be too hard. Give me a bit as I finish another task here at work first.
__________________
-----------------------------------------------------
The more knowledge one obtains the more there is too accumulate.....
-------------------------------------------------------
|
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | Quote:
Originally Posted by pennystrader I understand now. Ok I tested it and it bombed out on me too. I had not tried it yet. Let me mess with it and will post a working code here when I get a chance. it should not be too hard. Give me a bit as I finish another task here at work first. | This is a common issue in batch files.
Add the path the the ping EXE
C:\windows\system32\ping.exe 10.0.0.1
Depending on theinformation you are looking for this might be something you want to do with Windows PowerShell rather than simple batch files.
In an ideal world, what information do you want and how do you want it to be displayed?
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com |
| | | Senior Member
Join Date: Feb 2009 Location: Greenville SC
Posts: 2,821
Certifications: A+, Network+, Security+, MCTS:70-680 | Here is a neat one that we use: Quote:
@ipconfig/all | find "IP Address"
@ipconfig/all | find "Subnet Mask"
@ipconfig/all | find "Default Gateway"
@ipconfig/all | find "Host Name"
@ipconfig/all | find "DNS Suffix Search List"
@ipconfig/all | find "DNS Servers"
@ipconfig/all | find "Physical Address"
@ipconfig/all | find "DHCP Enabled"
@ipconfig/all | find "DHCP Server"
@ping 127.0.0.1
@echo.
@pause
|
__________________ Current Academic Studies: B.S. in Information Technology Certification Path for 2010-2011: Project+ -> MCITP:EA Reading: 3,280 of 10,000 page goal for 2010 What I am reading:
*Sybex: Project+ [100% finished]
*MSPress: 70-640: Active Directory, Configuring [0% finished]
*Secrets and Lies [40% finished]
*Where Wizards Stay Up Late: The Origins of the Internet [50% finished]
|
| | | Senior Member
Join Date: Dec 2006 Location: Ontario
Posts: 1,006
Certifications: A+, Net+, MCP, CCDP, CCNP, CCSA | Where are you running this file from?
If you are running it from your desktop, it wont work unless you have ping.exe on your desktop as well.
So, try putting this batch file in system32 and see what it does. (or copy ping.exe to your desktop).
See what I meanz?
EDIT: PastaMan beat me to it haha |
| | | Virtually in the shadows
Join Date: Oct 2008 Location: Peoria, IL
Posts: 140
Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0 | Ping Script Ok here is a working ping script that will append the date and you just put your one server or every machine you want in a filed named computerlist.txt in the same directory as the batch file. Let me know if this works for you. I ran it on 20 machines here and it worked as expected. It opens notepad at the end and gives you the results.
@echo off
(Set InputFile=c:\computerlist.txt)
title,Pinging list of computers
::datestamp
for /f "tokens=2-4 skip=1 delims=(-./)" %%i in ('echo.^|date') do (
for /f "tokens=1-4 delims=-./ " %%m in ('date /t') do (
(set dow=%%m)&(set %%i=%%n)&(set %%j=%%o)&(set yy=%%p) ) )
For /F "tokens=1,2 delims=:, " %%i in ('TIME /T') Do (Set HHMM=%%i%%j)
(Set OutputFile=c:\Pinglog %yy%-%mm%-%dd% %HHMM%.txt)
If Exist "%OutputFile%" Del "%OutputFile%"
For /F "eol=;" %%* in ('type "%InputFile%"') do (
>>"%OutputFile%" (echo.&echo.---------------&(
echo.%%*;&(ping -a -n 2 -w 750 %%* | Find "."))
)&echo.done %%*,)
::check
start notepad.exe %OutputFile%
__________________
-----------------------------------------------------
The more knowledge one obtains the more there is too accumulate.....
-------------------------------------------------------
|
| | | Member
Join Date: Jan 2009
Posts: 72
| it works now thanks guys
Last edited by mrblackmamba343; 12-30-2009 at 03:47 PM.
|
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | Check that out Veritas.... I know you looooove PowerShell! Code: $hostInfo=Get-WmiObject-classwin32_networkadapterconfiguration-namespace"root\CIMV2" | where-object-filterscript { $_.IPEnabled -eq‘True’-and$_.ServiceName -eq‘E100B’ }
write-host"IPAddress.......:"$hostInfo.IPAddress
Write-Host"Subnet Mask.....:"$hostInfo.IPSubnet
Write-Host"DNS Hostname....:"$hostInfo.DNSHostName
Write-Host"Default Gateway.:"$hostInfo.DefaultIPGateway
Write-Host"DNS Hostname....:"$hostInfo.DNSHostName
Write-Host"DNS Servers.....:"$hostInfo.DNSServerSearchOrder
$ping=New-ObjectSystem.Net.NetworkInformation.Ping;
$DFG=$ping.Send($hostInfo.DefaultIPGateway)
if($DFG.Status -eq"Success")
{
Write-Host"The system appears to have connectivity to the Default Gateway."
}
else
{
Write-Host"Unable to Ping the Default Gateway."-ForegroundColorRed
}
$DNSServers= [regex]::Split($hostInfo.DNSServerSearchOrder, " " )
foreach($serverin$DNSServers)
{
if($DFG.Status -eq"Success")
{
Write-Host"The system appears to have connectivity to the DNS Server "$server"."
}
else
{
Write-Host"Unable to Ping the DNS Server "$server"."-ForegroundColorRed
}
}
$google=$ping.Send("8.8.8.8")
if($google.Status -eq"Success")
{
Write-Host"The system appears to have connectivity to the Internet."
}
else
{
Write-Host"Unable to Ping the Internet."-ForegroundColorRed
}
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com |
| | | Senior Member
Join Date: Feb 2009 Location: Greenville SC
Posts: 2,821
Certifications: A+, Network+, Security+, MCTS:70-680 | Slickkkkkkkkkkkkkkkk 
__________________ Current Academic Studies: B.S. in Information Technology Certification Path for 2010-2011: Project+ -> MCITP:EA Reading: 3,280 of 10,000 page goal for 2010 What I am reading:
*Sybex: Project+ [100% finished]
*MSPress: 70-640: Active Directory, Configuring [0% finished]
*Secrets and Lies [40% finished]
*Where Wizards Stay Up Late: The Origins of the Internet [50% finished]
|
| | | Member
Join Date: Jan 2009
Posts: 72
| one last question. Does a task scheduled at task manager work when I'm logged off? |
| | | Senior Noob
Join Date: Jul 2009
Posts: 2,023
Certifications: Beer+ | Since when does ping need to be in the same directory?
Ive used tons of CLI tools that reside in system32 in my batch files without ever specifying the full path or copying said exe into the current working directory.
__________________ I got a fortune cookie that said "Outlook not so good" and I thought to myself "Yeah...but Microsoft sells it anyway." |
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | Quote:
Originally Posted by Hyper-Me Since when does ping need to be in the same directory?
Ive used tons of CLI tools that reside in system32 in my batch files without ever specifying the full path or copying said exe into the current working directory. | When I run defrag through a batch file I frequently get this problem. I'm not sure why.
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com
Last edited by RobertKaucher; 12-30-2009 at 05:43 PM.
|
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | Quote:
Originally Posted by mrblackmamba343 one last question. Does a task scheduled at task manager work when I'm logged off? | You need to set the task to run as a specific user account.
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com |
| | | Member
Join Date: Jan 2009
Posts: 72
| Quote:
Originally Posted by RobertKaucher You need to set the task to run as a specific user account. | yes I have already done that. I'm an administrator on the server |
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | Quote:
Originally Posted by mrblackmamba343 yes I have already done that. I'm an administrator on the server | If you look at the task tab of the task's properties on the lower, left corner there is a box that says something like "Run only if logged on." You want to be sure that is not checked.
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com |
| | | Member
Join Date: Jan 2009
Posts: 72
| Quote:
Originally Posted by RobertKaucher If you look at the task tab of the task's properties on the lower, left corner there is a box that says something like "Run only if logged on." You want to be sure that is not checked. | Thats is unchecked so I assume now that I'm set! |
| | | Senior Member Registered Member
Join Date: Mar 2007
Posts: 365
Certifications: CCNA,CCNP,A+,security+, Network+, MCP | sorry to hijack your thread but I have always wondered this about task manager maybe someone can help answer for me.
If userA has a task running and userB logs on can userB see whats going on assuming UserB doesn't check the task scheduler or it will run in the background?
__________________
RHCT.........loading
CCVP.........loading
CIPT 4.0 ......done
Must be an RHCT or RHCE by the end of the year
Last edited by nice343; 12-30-2009 at 06:09 PM.
|
| | | Standard Nerd
Join Date: Dec 2007 Location: Lebanon, Ohio - USA
Posts: 2,042
Certifications: Too many evidently... | The task will be displayed in Task Manager if they view the processes tab and click the "Show processes from all users."
It will not generally be displayed as a visible, active window.
__________________
WIP: 70-453 (DBA 2008 Upgrade)
Next: 70-433 and 70-451 MCITP: Database Developer; 70-445 and 70-446 MCITP: Business Intelligence Developer
--- Quote:
Originally Posted by knwminus You have to be willing to do what they won't to get what they don't. This is my way of the ninja. | http://elementalsql.blogspot.com |
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | All times are GMT. The time now is 07:00 AM. | |