Solved

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

Posted on 2008-10-16
2
759 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
  • 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Problem to skip loop 6 55
excel:  cumulative data 13 59
Help on VBSCript Font and color 1 68
Copy XML file and strip off certain elements 4 39
Recently I finished a vbscript that I thought I'd share.  It uses a text file with a list of server names to loop through and get various status reports, then writes them all into an Excel file.  Originally it was put together for our Altiris server…
This script will sweep a range of IP addresses (class c only, 255.255.255.0) and report to a log the version of office installed. What it does: 1.)      Creates log file in the directory the script is run from (if it doesn't already exist) 2.)      Sweep…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

895 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now