Login | |
|
 |
RE: Ping & Excute Script - 4/15/2007 1:25:03 PM
|
|
 |
|
| |
dm_4ever
Posts: 2637
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1") Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then WScript.Echo "google was reachable...call bat" End If End If Next
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/15/2007 2:16:56 PM
|
|
 |
|
| |
Sc4rEye
Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
|
Oh, that would do it. I have no clue where to add what. I was just reading your code and trying to learn from it. Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1") Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then WScript.Echo "google was reachable...call bat" End If End If Next I tried this....... Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1") Dim strIP For Each strIP In arrIPAddr If Reachable("arrIpAddr") Then If Not Reachable(strIP) Then If Reachable("www.google.com") Then WScript.Echo "google was reachable...call bat" End If End If Finish But still no good. Again, I am learning, Sorry for being a total newb. Any guidance is getting this setup is appreciated. Thanks ScarEye
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/15/2007 3:08:51 PM
|
|
 |
|
| |
Sc4rEye
Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
|
Okay, I am acutally learning something.... Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1", "192.168.80.1") <--- I added this IP and it's dead on purpose (192.168.80.1) THEN...... Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then WScript.Echo "google was reachable...call bat" <---- This line is executed. However, I would like this line to just execute c:\myfile.bat and move on to the next IP. End If End If Next Function Reachable(strComputer) ' On Error Resume Next Dim objShell, objExec, strCmd, strTemp strCmd = "ping -n 1 " & strComputer Set objShell = CreateObject("WScript.Shell") Set objExec = objShell.Exec(strCmd) strTemp = UCase(objExec.StdOut.ReadAll) If InStr(strTemp, "REPLY FROM") Then Reachable = True Else Reachable = False End If End Function I tried Wscript.execute, But that doesn't work because it doesn't know what Wscript.execute is. So how would I tell the script, HEY! run my batch file now and move on ? Thanks dm_4ever
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/16/2007 12:49:43 AM
|
|
 |
|
| |
dm_4ever
Posts: 2637
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
|
Dim oShell : Set oShell = WScript.CreateObject ("WSCript.shell") Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.6.1") Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then oShell.Run "c:\somefile.bat" End If End If Next Function Reachable(strComputer) ' On Error Resume Next Dim objShell, objExec, strCmd, strTemp strCmd = "ping -n 1 " & strComputer Set objShell = CreateObject("WScript.Shell") Set objExec = objShell.Exec(strCmd) strTemp = UCase(objExec.StdOut.ReadAll) If InStr(strTemp, "REPLY FROM") Then Reachable = True Else Reachable = False End If End Function
_____________________________
dm_4ever My philosophy: K.I.S.S - Keep It Simple Stupid Read Me: http://www.visualbasicscript.com/m_24727/tm.htm Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/16/2007 5:49:30 AM
|
|
 |
|
| |
Country73
Posts: 732
Score: 10
Joined: 8/25/2004
From: USA
Status: offline
|
You need to run the script in CSCRIPT mode. I'm sure you can find several examples on how to force your script to run in that mode, but this is what I like to use. IF INSTR(1, Wscript.FullName, "CScript", VBTEXTCOMPARE) = 0 THEN oShell.Run "cscript """ & Wscript.ScriptFullName & """", 0, FALSE Wscript.Quit END IF This needs to go up towards the very top of your script right after: Dim oShell : Set oShell = WScript.CreateObject ("WSCript.shell")
|
|
| |
|
|
|
 |
RE: Ping & Excute Script - 4/16/2007 6:30:07 AM
|
|
 |
|
| |
Sc4rEye
Posts: 26
Score: 0
Joined: 10/28/2005
Status: offline
|
Thanks Country73 that worked perfectly. Now, I was putting this all together with everything I have. And I realized something. I should have thought of this before, but I got caught up in this whole scripting thing, plus a few other projects I got going on. Anyway this is the problem. When a IP fails. It starts running the script myfile.bat, GREAT! BUT, BUT, this is the problem depending on which IP fails it has to execute that particular .bat file. For example If 192.168.2.1 fails ping it would have to run c:\myfile2.bat If 192.168.3.1 fails ping it would have to run c:\myfile3.bat If 192.168.4.1 passes ping then move to the next IP. I don't know if this possible, any suggestions ? Thanks, again & again & again (x infinity) ScarEye Dim oShell : Set oShell = WScript.CreateObject ("WSCript.shell") IF INSTR(1, Wscript.FullName, "CScript", VBTEXTCOMPARE) = 0 THEN oShell.Run "cscript """ & Wscript.ScriptFullName & """", 0, FALSE Wscript.Quit END IF Dim arrIPAddr : arrIPAddr = Array("192.168.1.1", "192.168.2.1", "192.168.3.1", _ "192.168.4.1", "192.168.5.1", "192.168.222.1") Dim strIP For Each strIP In arrIPAddr If Not Reachable(strIP) Then If Reachable("www.google.com") Then oShell.Run "c:\somefile.bat" End If End If Next Function Reachable(strComputer) ' On Error Resume Next Dim objShell, objExec, strCmd, strTemp strCmd = "ping -n 1 " & strComputer Set objShell = CreateObject("WScript.Shell") Set objExec = objShell.Exec(strCmd) strTemp = UCase(objExec.StdOut.ReadAll) If InStr(strTemp, "REPLY FROM") Then Reachable = True Else Reachable = False End If End Function
|
|
| |
|
|
|
|
|