Solved

How to ping IP write error to log if failed and continue with script if successful

Posted on 2008-10-16
2
771 Views
Last Modified: 2012-05-05
I have written a script to check ping before checking for a file status. If the ping is successful continue if the ping fails write to error log. On successful ping check if a file exists, if it does not exsist log the error. If is does not exsist write the error to same error log file.

I am getting the error "expected Then on line 16", but I cannot figure out why?
Const ForReading = 1
Const OverwriteExisting = TRUE
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.DeleteFile("C:\Scripts\Look4File\File_Status_Err.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Look4File\pclistfile_Corp.txt")
Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    Set WshShell = CreateObject("WScript.Shell")
    PINGFlag = Not CBool(WshShell.run("ping -n 2 " & strComputer,0,True))
      If PINGFlag = True Then
	StrPath = "C:\Iris\Settled\Settled.csv"
	On Error Resume Next
        Set oFSO = CreateObject("scripting.FileSystemObject")
        If 0FSO.FileExists(strPath) Then
		Msgbox "it's there"
	ELSE	
		'Write information to Text File
		Fstat = strComputer & ": " & "Cannot Find file, or file does not exist!"
 
		Set FSO = CreateObject("Scripting.FileSystemObject")
		Set WriteErr = FSO.OpenTextFile("File_Status_Err.txt", 8, True)
		WriteErr.WriteLine(Fstat)
		WriteErr.Close
	End If
      ELSE 
	On Error Resume Next
        Set oFSO = CreateObject("scripting.FileSystemObject")
        If 0FSO.FileExists(strPath) Then
        	
		'Write information to Text File
		Fstat = strComputer & ": " & "System did not ping!"
 
		Set FSO = CreateObject("Scripting.FileSystemObject")
		Set WriteErr = FSO.OpenTextFile("File_Status_Err.txt", 8, True)
		WriteErr.WriteLine(Fstat)
		WriteErr.Close
	End If
      End If
Loop
 
MsgBox "All Done"

Open in new window

0
Comment
Question by:Tacobueno
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 21

Expert Comment

by:AmazingTech
ID: 22734631
Line 16: 0FSO you type 'Zero'FSO same with Line 30.
0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 125 total points
ID: 22734651
Fixed code.
Const ForReading = 1
Const OverwriteExisting = TRUE
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject")
FSO.DeleteFile("C:\Scripts\Look4File\File_Status_Err.txt")
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Scripts\Look4File\pclistfile_Corp.txt")
Do Until objFile.AtEndOfStream
    strComputer = objFile.ReadLine
    Set WshShell = CreateObject("WScript.Shell")
    PINGFlag = Not CBool(WshShell.run("ping -n 2 " & strComputer,0,True))
      If PINGFlag = True Then
	StrPath = "C:\Iris\Settled\Settled.csv"
	On Error Resume Next
        Set oFSO = CreateObject("scripting.FileSystemObject")
        If oFSO.FileExists(strPath) Then
		Msgbox "it's there"
	ELSE	
		'Write information to Text File
		Fstat = strComputer & ": " & "Cannot Find file, or file does not exist!"
 
		Set FSO = CreateObject("Scripting.FileSystemObject")
		Set WriteErr = FSO.OpenTextFile("File_Status_Err.txt", 8, True)
		WriteErr.WriteLine(Fstat)
		WriteErr.Close
	End If
      ELSE 
	On Error Resume Next
        Set oFSO = CreateObject("scripting.FileSystemObject")
        If oFSO.FileExists(strPath) Then
        	
		'Write information to Text File
		Fstat = strComputer & ": " & "System did not ping!"
 
		Set FSO = CreateObject("Scripting.FileSystemObject")
		Set WriteErr = FSO.OpenTextFile("File_Status_Err.txt", 8, True)
		WriteErr.WriteLine(Fstat)
		WriteErr.Close
	End If
      End If
Loop
 
MsgBox "All Done"

Open in new window

0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question