?
Solved

Check URL if Accessible Via Scripting

Posted on 2011-05-04
8
Medium Priority
?
327 Views
Last Modified: 2012-06-27
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
0
Comment
Question by:mmoya
8 Comments
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35690581
Alternative: free websites that do this. I use http://www.siteuptime.com/

Just a thought
0
 

Author Comment

by:mmoya
ID: 35690599
Good to have...but spending is not an option for us right now... Thanks though.
0
 
LVL 39

Expert Comment

by:Aaron Tomosky
ID: 35690615
They have a free option. That's the one I use. If you want more functionality then they have paid options.
0
Creating Active Directory Users from a Text File

If your organization has a need to mass-create AD user accounts, watch this video to see how its done without the need for scripting or other unnecessary complexities.

 
LVL 12

Expert Comment

by:FDiskWizard
ID: 35693010
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
 
LVL 10

Accepted Solution

by:
GlobaLevel earned 668 total points
ID: 35693199
...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
 
LVL 10

Assisted Solution

by:ReneGe
ReneGe earned 664 total points
ID: 35695035
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
 

Author Comment

by:mmoya
ID: 35706594
Ok, will test it. Thank you for your assistance! Will let you all know..
0
 
LVL 11

Assisted Solution

by:marek1712
marek1712 earned 668 total points
ID: 35715926
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

Featured Post

A Cyber Security RX to Protect Your Organization

Join us on December 13th for a webinar to learn how medical providers can defend against malware with a cyber security "Rx" that supports a healthy technology adoption plan for every healthcare organization.

Question has a verified solution.

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

My attempt to use PowerShell and other great resources found online to simplify the deployment of Office 365 ProPlus client components to any workstation that needs it, regardless of existing Office components that may be needing attention.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Loops Section Overview

809 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