Check File (created) Age in multiple folders; If over XX minutes, Alert via Email

Author Message
billiehawkins

  • Total Posts : 3
  • Scores: 0
  • Reward points : 0
  • Joined: 11/17/2011
  • Status: offline
Check File (created) Age in multiple folders; If over XX minutes, Alert via Email Thursday, November 17, 2011 10:57 AM (permalink)
0
[Helpful answer received] / [List Solutions Only]
I have a list of directories that get files added to by other users on my network.

I would like a script (triggered by scheduled task) that would detect if there are files in these folders older than 15 minutes, and send me an email.

I am able to run Batch/DOS, Python, Perl, or VBS - I have them all installed on the server. As long as they can be triggered from Scheduled task.

Example:
C:\UsersFTP\JoeS\FromCustomer\ <files dropped here>
C:\UsersFTP\Mark\FromCustomer\ <files dropped here>
C:\UsersFTP\Robbie\FromCustomer\ <files dropped here>
C:\UsersFTP\Tammy\FromCustomer\ <files dropped here>


  • - Check every 15 mintues if any FILES exist in these directories (along with 50 more).
  • - It should ignore folders.
  • - If No, quit.
  • - If yes, email user@emailaddress.com and notify that files are waiting to be reviewed.
  • - The scheduled task can run it every 15 minutes.
  • - I would like it to only send ONE email, no matter how many files are waiting.

Example notification: (the XX are variables)

= = = = =
From: Notifer@youremail.com
To: user@emailaddress.com
Subject: Files in FromCustomer are waiting


You Have files that are waiting since  xx:xx:xx PM  (over XX minutes).

The files are located in:

C:\UsersFTP\Tammy\FromCustomer\
C:\UsersFTP\Robbie\FromCustomer\

Please process or remove them. Thank you.

= = = = =

I have been looking at doing this in Batch, but I just don't think it is capable... I was hoping that there was an easier way, but my VBS is limited... thoughts, help?


 
#1
    59cobalt

    • Total Posts : 969
    • Scores: 91
    • Reward points : 0
    • Joined: 7/17/2011
    • Status: offline
    Re:Check File (created) Age in multiple folders; If over XX minutes, Alert via Email Thursday, November 17, 2011 3:22 PM (permalink)
    0
    billiehawkins
    I have a list of directories that get files added to by other users on my network.

    I would like a script (triggered by scheduled task) that would detect if there are files in these folders older than 15 minutes, and send me an email.
    Set fso = CreateObject("Scripting.FileSystemObject")
    userlist = Array("JoeS", "Mark", "Robbie", "Tammy", ...)
    
    For Each user In userlist
     If fso.GetFolder("C:\UsersFTP\" & user & "\FromCustomer").Files.Count > 0 Then
     ' send mail
     End If
    Next
    Check the FAQ for sample code for sending e-mails.

    billiehawkins
    I have been looking at doing this in Batch, but I just don't think it is capable...
    You think wrong.
    @echo off
    
    setlocal EnableDelayedExpansion
    
    set userlist=JoeS Mark Robbie Tammy ...
    
    for %%u in (%userlist%) do (
     dir /a:-d "C:\UsersFTP\%%u\FromCustomer" >nul 2>&1
     if !errorlevel! neq 0 rem send mail
    )
    
    endlocal
    You can use bmail or Blat to send mail from the script.
     
    #2
      billiehawkins

      • Total Posts : 3
      • Scores: 0
      • Reward points : 0
      • Joined: 11/17/2011
      • Status: offline
      Re:Check File (created) Age in multiple folders; If over XX minutes, Alert via Email Friday, November 18, 2011 9:26 AM (permalink)
      0
      I understand how that will report files in a directory, but they need to detect them after 15 minutes... which is the issue i am having.
       
      59cobalt





      For Each user In userlist
      If fso.GetFolder("C:\UsersFTP\" & user & "\FromCustomer").Files.Count > 0 Then
      ' send mail
      End If
      Next[/code]Check the FAQ for sample code for sending e-mails.

      billiehawkins
      I have been looking at doing this in Batch, but I just don't think it is capable...
      You think wrong.
      @echo off 
       
       setlocal EnableDelayedExpansion 
       
       set userlist=JoeS Mark Robbie Tammy ... 
       
       for %%u in (%userlist%) do ( 
       dir /a:-d "C:\UsersFTP\%%u\FromCustomer" >nul 2>&1 
       if !errorlevel! neq 0 rem send mail 
       ) 
       
       endlocal
      You can use bmail or Blat to send mail from the script.


       
      #3
        59cobalt

        • Total Posts : 969
        • Scores: 91
        • Reward points : 0
        • Joined: 7/17/2011
        • Status: offline
        Re:Check File (created) Age in multiple folders; If over XX minutes, Alert via Email Friday, November 18, 2011 11:13 AM (permalink)
        0
        [This post was marked as helpful]
        billiehawkins
        I understand how that will report files in a directory, but they need to detect them after 15 minutes... which is the issue i am having.
        hasOldFile = False
        
        For Each user In userlist
         For Each f In fso.GetFolder("C:\UsersFTP\" & user & "\FromCustomer").Files
         If DateDiff("n", f.DateLastModified, Now) > 15 Then hasOldFile = True
         Next
        Next
        
        If hasOldFile Then 'send mail

        Calculating time differences in batch is possible, but really ugly. Not worth the trouble.
         
        #4
          billiehawkins

          • Total Posts : 3
          • Scores: 0
          • Reward points : 0
          • Joined: 11/17/2011
          • Status: offline
          Re:Check File (created) Age in multiple folders; If over XX minutes, Alert via Email Wednesday, November 23, 2011 6:42 AM (permalink)
          0
          I was able to come up with a solution: Perhaps it will help others.
           
           
           
           
          '------------------- Billie Hawkins  ---------------------
          '------------------- Check Files VBS ---------------------



          'Dim ShowFolderList(folderspec)
          Set oFSO = CreateObject("Scripting.FileSystemObject")

          Dim folderspec
          Dim fs, f, f1, fc, s
          folderspec = "C:\Users\"
          Set fs = CreateObject("Scripting.FileSystemObject")
          Set f = fs.GetFolder(folderspec)
          Set fc = f.SubFolders
          For Each f1 in fc
          s = s & f1.name
          's = s &  vbCrLf




          sPath = "C:\Users\" & f1.name & "\FromCustomer"
          'wscript.echo sPath

          Set oFolder = oFSO.GetFolder(sPath)
          On Error Resume Next
          Set oFiles = oFolder.Files

          If oFiles.Count > 0 Then

          ' Enumerate the files in the folder looking for files updated
          ' within the last xx minutes. If such a file is found, exit the loop.

          bolFileIsNewEnough = False  ' init value
          For Each oFile In oFiles
          On Error Resume Next
          dFileModDate = oFile.DateLastModified
          If Err.Number = 0 Then
          If DateDiff("n", dFileModDate, Now) < 15 Then
          bolFileIsNewEnough = True
          Exit For
          End If
          End If
          Next
          On Error Goto 0

          If Not bolFileIsNewEnough Then
          Set objEmail = CreateObject("CDO.Message")
          objEmail.From = "File-Alert@msbinfo.com"
          objEmail.To = "billie.hawkins@email.com"
          objEmail.Subject = "Error: Files sitting over 15 minutes. "
          objEmail.Textbody = sPath & " has files older than 15 Min." & VBCRLF & " Please check."


          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "my.smtp.com"
          objEmail.Configuration.Fields.Item _
          ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
          objEmail.Configuration.Fields.Update
          objEmail.Send
          End if

          Else
          'WScript.Echo "Directory is empty"
          End If
          Next

          '--------------------Billie Check Files VBS----------------------
           
          #5

            Online Bookmarks Sharing: Share/Bookmark

            Jump to:

            Current active users

            There are 0 members and 1 guests.

            Icon Legend and Permission

            • New Messages
            • No New Messages
            • Hot Topic w/ New Messages
            • Hot Topic w/o New Messages
            • Locked w/ New Messages
            • Locked w/o New Messages
            • Read Message
            • Post New Thread
            • Reply to message
            • Post New Poll
            • Submit Vote
            • Post reward post
            • Delete my own posts
            • Delete my own threads
            • Rate post

            2000-2012 ASPPlayground.NET Forum Version 3.9