• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 153
  • Last Modified:

VB Script - Check Text file for date

Hi ,
I want to put a script together that checks an output from another system ( output is the date a service ran in a text file )
Need to pull the date , do a compare and send an email if theres a gap of more than 50 mins between now() and the time in the file.

Will scedule the script to run every 5 min...

Any ideas?

Cheers!
0
stephengriffin
Asked:
stephengriffin
  • 3
  • 2
1 Solution
 
gecko_au2003Commented:
In this text file is there only one date at any one time or are there multiple dates that have to be searched through or do you just take the last date that is in there out of all of them or what ?
0
 
stephengriffinAuthor Commented:
Hi , the text will be replaced each time within the file.. ie it will just be a date time (now function)

thanks!
0
 
ADSaundersCommented:
Hi stephengriffin,
This should do the trick. Please note I haven't actually tested this script, but have extracted (and modified) code from working (VB) software on our site. Don't forget to make the changes indicated in the code before running. Just copy & paste into a .vbs file (Suggest DateCheck.vbs), edit it, and run it.

Regards .. Alan

Private Const ForReading = 1
Private Const MapiTo = 1
Private Const Mapicc = 2
Private Const MapiBcc = 3
Private Const fPath = "C:\Time.log" ' Put path to file in here
Dim fso, f, DateAndTime, OSession, Omessage, Recip
Set fso = CreateObject("Scripting.filesystemobject")
Set f = fso.OpenTextFile(FPath, ForReading)
While Trim(f.ReadLine) = "" ' Skip empty lines
Wend
DateAndTime = CDate(Trim(f.ReadLine))
f.Close
Set f = Nothing
If DateDiff("m",DateAndTime, Now) > 50 Then
      Set OSession = CreateObject(MAPI.Session)
      ' Change anything in '<>' to match your environment This is the Exchange account sending the message
      OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
      'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
      Set OMessage = OSession.Outbox.Messages.Add
      ' Repeat this section for all recipients
      Set Recip = OMessage.Recipients.Add
      Recip.Name = "<Who's it going to>"
      Recip.Type = MapiTo ' Subsequent recipients should be Mapicc oe MapiBcc
      Recip.Resolve
      ' To here
      Set Recip = Nothing
      OMessage.Subject = "This is your message Subject"
      OMessage.Text = "This is the message Body"
      OMessage.Text = OMessage.text & CHR(10) & "Add this if more than one line"
      OMessage.Update
      OMessage.Send
      Set OMessage = Nothing
      OSession.Logoff
      Set OSession = Nothing
End if

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
ADSaundersCommented:
Sorry left some extraneous code in there:
>    OSession.Logon ("", "", True, True, 0, False, "Orac" + CHR(10) + "Scheduler")
>     'OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")

Should be:
    OSession.Logon ("", "<password>", True, True, 0, False, "<Exchange Server>" + CHR(10) + "<Exchange Account>")
i.e delete the line with my test names in, and uncomment the other.

.. Alan
 
0
 
ADSaundersCommented:
Sorry again, we're checking for 50 months difference here:
If DateDiff("m",DateAndTime, Now) > 50 Then
Should be:
If DateDiff("n",DateAndTime, Now) > 50 Then

.. Alan
0
 
stephengriffinAuthor Commented:
Sorry Alan ! I thought id awared points!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now