Check URL if Accessible Via Scripting

Can someone provide assistance on how to run a scheduled task via batch or vbscript or powershell to check if URLs are accesible and if it's not, send email to certain users? Thank you!

URL#1 = \\test.domain.com\SYSVOL\test.domain.com\Policies\{0AEB8C64-8009-4DE5-9FDC-591EA275220F}\GPT.INI

URL#2 = \\test.domain.com\SYSVOL\test.domain.com\Policies\{0B3C35DD-14C8-42CD-A844-BC585A6BC7C6}\GPT.INI
mmoyaAsked:
Who is Participating?
 
GlobaLevelProgrammerCommented:
...well a little tough....you gotta do a work around....once the file is launch whether web file(.aspx..html)...or file dir (.exe,.txt) the vbscript loses focus of that document..unless it writes to another file..and it checks for a file there...however as FDisk mentioned you can verify if the path exists...here:


'Vars
Dim objFSO, objFileCopy, objFileDelete, dot, files, file
Dim strFilePath, strDestination, folder, subfolder, fileCount, strFolder
 
'Strings
strFilePath = "GPT.INI"
strFolder = "\\test.domain.com\SYSVOL\test.domain.com\Policies\{0AEB8C64-8009-4DE5-9FDC-591EA275220F}\"
 
set objFSO = CreateObject("Scripting.fileSystemObject") 
set folder = objFSO.getFolder(strFolder) 
	
'Parent folder Subroutine
For Each file In folder.files
    Set objFileCopy = objFSO.GetFile(file)
	   
	 
		
	If objFSO.FileExists(strDestination) Then
		wscript.echo objFileCopy
		WScript.Echo "Already there"
		wscript.quit
	End If
    Next 
 
Sub CheckExists(objFileCopy)
set folder = objFSO.getFolder(strDestination) 
 

End Sub



' ------------------------------------
' http://www.experts-exchange.com/Programming/Languages/Visual_Basic/Q_26366409.html?sfQueryTermInfo=1+10+30+exist+file+vbscript

'VBS RUNAS SCRIPT SAVE IT AS RUNAS_REMOTE_FILE_CHECK.VBS

strUser = "USER_NAME"
strDomain = "DOMAIN_NAME"
strCurPath = CreateObject("Scripting.FileSystemObject").GetAbsolutePathName(".")
strRunAs ="runas /savecred /user:" & strDomain & "\" & strUser&" " & Chr(34)& "cscript.exe \"& Chr(34)& strCurPath & "\REMOTE_FILE_CHECK.VBS" & Chr(34)

Set WshShell = CreateObject("WScript.Shell")
strRunPath = strRunAs
WshShell.Run (strRunPath)

'========================================================================================================

'VBS SCRIPT - SAVE IT AS REMOTE_FILE_CHECK.VBS

strFilePath = "PATH FOR THE FILE"

Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FileExists(strFilePath) Then
    Wscript.Echo "File does exist."
Else
    Wscript.Echo "File does NOT exist."
End If

Open in new window

0
 
Aaron TomoskySD-WAN SimplifiedCommented:
Alternative: free websites that do this. I use http://www.siteuptime.com/

Just a thought
0
 
mmoyaAuthor Commented:
Good to have...but spending is not an option for us right now... Thanks though.
0
How do you know if your security is working?

Protecting your business doesn’t have to mean sifting through endless alerts and notifications. With WatchGuard Total Security Suite, you can feel confident that your business is secure, meaning you can get back to the things that have been sitting on your to-do list.

 
Aaron TomoskySD-WAN SimplifiedCommented:
They have a free option. That's the one I use. If you want more functionality then they have paid options.
0
 
FDiskWizardCommented:
That isn't a URL, it's a UNC path.
You need a File Exists sort of script. Sorry, no time at the moment...
0
 
ReneGeCommented:
Just did this for you.

I did not test it but it should work first hand.

Let me know.

You will need to get Blat to send emails:
http://sourceforge.net/projects/blat/files/Blat%20Full%20Version/Blat%20v2.6.2/blat262.full.zip/download

Cheers,
Rene

@ECHO OFF

SET URL.1=\\test.domain.com\SYSVOL\test.domain.com\Policies\{0AEB8C64-8009-4DE5-9FDC-591EA275220F}\GPT.INI
SET URL.2=\\test.domain.com\SYSVOL\test.domain.com\Policies\{0B3C35DD-14C8-42CD-A844-BC585A6BC7C6}\GPT.INI

:Home

FOR /F "DELIMS=" %%A IN ('SET URL.') DO IF NOT EXIST "%%A" CALL :SendEmail "%%A"

REM PAUSE FOR ARROUND 1 MIN
	PING -n 60 127.0.0.1 >NUL

Goto Home

:SendEmail
SET Emailer=blat.exe
SET EmailTo=user@emailaddress.com
SET EmailFrom=sysadmin@emailaddress.com
SET EmailSubject=File is missing
SET EmailServer=smtp.server.com
SET EmailBody=%~1

"%Emailer%" -body "%EmailBody%" -to "%EmailTo%" -f "%EmailFrom%" -s "%EmailSubject% %time%" -server "%EmailServer%" -debug -timestamp -log "Email.log" >NUL

EXIT /b

Open in new window

0
 
mmoyaAuthor Commented:
Ok, will test it. Thank you for your assistance! Will let you all know..
0
 
marek1712Commented:
The PowerShell way:
Get-ChildItem \\SERVER\share -ErrorVariable err -ErrorAction SilentlyContinue
if ($err -ne $null) 
{
    $EmailFrom = "mail@server.com"
    $EmailTo = "mail2@server.com" 
    $Subject = "Notification from XYZ" 
    $Body = "Path unavailable" 
    $SMTPServer = "smtp.server.com" 
    $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
    $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password"); 
    $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
}

Open in new window

Got some info from this post as it's bit tricky with SMTP server not being Exchange one (therefore I had some problems with Send-MailMessage)
http://stackoverflow.com/questions/1252335/send-mail-via-gmail-with-powershell-v2s-send-mailmessage/2250309#2250309
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.