Home  
  Microsoft  
  Cisco  
  CompTIA  
  CWNP  
  InfoSecurity  
  Forums  
  Blogs  
  Topsites  
  Watch free videos online  
     
  Subnet Calculator  
  Online Degrees  
  Exam Vouchers  
  Free Magazines  
     

  Watch free videos online  
   

 

Register Practice Exams TechNotes Members List Search Today's Posts Mark Forums Read
Go Back   TechExams.net IT Certification Forums > General > Off-Topic
Reply
 
Thread Tools
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 01:02 PM   #1 (permalink)
Default 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.
mrblackmamba343 is offline   Reply With Quote

Login/register to remove this advertisement.
Senior Member
 
ConstantlyLearning's Avatar
 
Join Date: Dec 2006
Location: Dublin, Ireland
Posts: 335

Certifications: CCNA, CCENT, CWNA, Security+, Network+, A+, MCP, MCSA
ConstantlyLearning will become famous soon enough
Old 12-30-2009, 01:25 PM   #2 (permalink)

Quote:
Originally Posted by mrblackmamba343 View Post
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

ConstantlyLearning is offline   Reply With Quote
Virtually in the shadows
 
pennystrader's Avatar
 
Join Date: Oct 2008
Location: Peoria, IL
Posts: 140

Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0
pennystrader will become famous soon enough
Old 12-30-2009, 01:43 PM   #3 (permalink)
Default 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.....

-------------------------------------------------------

pennystrader is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 01:52 PM   #4 (permalink)

Quote:
Originally Posted by ConstantlyLearning View Post
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?

mrblackmamba343 is offline   Reply With Quote
Virtually in the shadows
 
pennystrader's Avatar
 
Join Date: Oct 2008
Location: Peoria, IL
Posts: 140

Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0
pennystrader will become famous soon enough
Old 12-30-2009, 02:52 PM   #5 (permalink)
Default 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.....

-------------------------------------------------------

pennystrader is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 02:54 PM   #6 (permalink)

Quote:
Originally Posted by pennystrader View Post
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.
mrblackmamba343 is offline   Reply With Quote
Virtually in the shadows
 
pennystrader's Avatar
 
Join Date: Oct 2008
Location: Peoria, IL
Posts: 140

Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0
pennystrader will become famous soon enough
Old 12-30-2009, 02:57 PM   #7 (permalink)
Default 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.....

-------------------------------------------------------

pennystrader is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 03:02 PM   #8 (permalink)

Quote:
Originally Posted by pennystrader View Post
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

mrblackmamba343 is offline   Reply With Quote
Virtually in the shadows
 
pennystrader's Avatar
 
Join Date: Oct 2008
Location: Peoria, IL
Posts: 140

Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0
pennystrader will become famous soon enough
Old 12-30-2009, 03:10 PM   #9 (permalink)
Default 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.....

-------------------------------------------------------

pennystrader is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 03:22 PM   #10 (permalink)

Quote:
Originally Posted by pennystrader View Post
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 View Post
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

RobertKaucher is offline   Reply With Quote
Senior Member
 
veritas_libertas's Avatar
 
Join Date: Feb 2009
Location: Greenville SC
Posts: 2,821

Certifications: A+, Network+, Security+, MCTS:70-680
veritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to behold
Old 12-30-2009, 03:24 PM   #11 (permalink)

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]

veritas_libertas is offline   Reply With Quote
Senior Member
 
Join Date: Dec 2006
Location: Ontario
Posts: 1,006

Certifications: A+, Net+, MCP, CCDP, CCNP, CCSA
GT-Rob is a jewel in the roughGT-Rob is a jewel in the roughGT-Rob is a jewel in the roughGT-Rob is a jewel in the rough
Old 12-30-2009, 03:34 PM   #12 (permalink)

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

GT-Rob is offline   Reply With Quote
Virtually in the shadows
 
pennystrader's Avatar
 
Join Date: Oct 2008
Location: Peoria, IL
Posts: 140

Certifications: Security+, MCITP: Enterprise Messaging Administrator 2K7, MCSE:Security 2K3, VCP 3.5/4.0
pennystrader will become famous soon enough
Old 12-30-2009, 03:35 PM   #13 (permalink)
Default 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.....

-------------------------------------------------------

pennystrader is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 03:36 PM   #14 (permalink)

it works now thanks guys


Last edited by mrblackmamba343; 12-30-2009 at 03:47 PM.
mrblackmamba343 is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 04:51 PM   #15 (permalink)

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 View Post
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

RobertKaucher is offline   Reply With Quote
Senior Member
 
veritas_libertas's Avatar
 
Join Date: Feb 2009
Location: Greenville SC
Posts: 2,821

Certifications: A+, Network+, Security+, MCTS:70-680
veritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to beholdveritas_libertas is a splendid one to behold
Old 12-30-2009, 04:54 PM   #16 (permalink)

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]

veritas_libertas is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 05:27 PM   #17 (permalink)

one last question. Does a task scheduled at task manager work when I'm logged off?

mrblackmamba343 is offline   Reply With Quote
Senior Noob
 
Join Date: Jul 2009
Posts: 2,023

Certifications: Beer+
Hyper-Me is a glorious beacon of lightHyper-Me is a glorious beacon of lightHyper-Me is a glorious beacon of lightHyper-Me is a glorious beacon of lightHyper-Me is a glorious beacon of light
Old 12-30-2009, 05:38 PM   #18 (permalink)

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."

Hyper-Me is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 05:41 PM   #19 (permalink)

Quote:
Originally Posted by Hyper-Me View Post
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 View Post
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.
RobertKaucher is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 05:41 PM   #20 (permalink)

Quote:
Originally Posted by mrblackmamba343 View Post
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 View Post
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

RobertKaucher is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 05:43 PM   #21 (permalink)

Quote:
Originally Posted by RobertKaucher View Post
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

mrblackmamba343 is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 05:53 PM   #22 (permalink)

Quote:
Originally Posted by mrblackmamba343 View Post
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 View Post
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

RobertKaucher is offline   Reply With Quote
Member
 
Join Date: Jan 2009
Posts: 72

mrblackmamba343 is on a distinguished road
Old 12-30-2009, 06:01 PM   #23 (permalink)

Quote:
Originally Posted by RobertKaucher View Post
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!

mrblackmamba343 is offline   Reply With Quote
Senior Member
Registered Member
 
Join Date: Mar 2007
Posts: 365

Certifications: CCNA,CCNP,A+,security+, Network+, MCP
nice343 is on a distinguished road
Old 12-30-2009, 06:07 PM   #24 (permalink)

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.
nice343 is offline   Reply With Quote
Standard Nerd
 
RobertKaucher's Avatar
 
Join Date: Dec 2007
Location: Lebanon, Ohio - USA
Posts: 2,042

Certifications: Too many evidently...
RobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to beholdRobertKaucher is a splendid one to behold
Old 12-30-2009, 06:14 PM   #25 (permalink)

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 View Post
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

RobertKaucher is offline   Reply With Quote
Bookmarks
Go Back TechExams.net IT Certification Forums > General > Off-Topic
Reply


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT. The time now is 07:00 AM.

 
 
Featured Sponsors

TrainSignal - “Hands On” computer training for IT professionals. Network+ Training, MCSE, Cisco & more! Visit Train Signal’s free training site to get loads of Free Computer Training, videos, articles and practice exams.

Preplogic - Sign up now to get Unlimited Access to PrepLogic's entire video training library. Enjoy open access to Microsoft Server 2008, CCNA, CISSP®, PMP and many more. Get Unlimited Access

 

Powered by vBulletin® Version 3.8
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
TechExams.net © 2002 - 2010