Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to open up a text file and pick up a number 2

Status
Not open for further replies.

gogopoppy

Instructor
Mar 6, 2005
114
CA
Hi,

I have a log file generated everyday which is called Log followed by the date 03122009 so the name is Log03122009.txt
Its on the same machine where I'm running my code C:\Logs\.

On the second line (not at the beginning) I have the following:
Record Counts: 333

I would like to open up the log file for today, compare the number with yesterday and send an email to my email address if it is not higher today than yesterday.

The record count should always increase in every log but sometimes it doesn't and as I said I'd like windows to send an email (via outlook?) to notify me so I don't have to keep checking each day.

Can anyone help me with the code necessary to:
Open the text file
Find the number in the text file
Email myself something through outlook

Any pointers would be great

tx

grd
 
Hi PHV,

Thanks for the link. I needed this to get started. Now I have

' VBScript: Trying to open and read a line
Dim fso
Dim MyFile
Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso_OpenTextFile("c:\Logs\testfile.txt", ForReading, True)
MyFile.Close

I'm trying to use OpenTextFile as I don't need to write anything and I'm getting an error - invalid procedure call on line 4 - the opentextfile. The file exists.

Any ideas?

Tx agaom

 
Hi,

You'll need to include the constant values for the IOMODE parameter (or sub in the value's in the OpenTextFile), try:
Code:
Dim myfile
Dim str
Dim fso

[red]Const ForReading = 1, ForWriting = 2, ForAppending = 8[/red]

Set fso = CreateObject("Scripting.FileSystemObject")
Set myfile = fso.OpenTextFile("c:\Logs\testfile.txt", [red]ForReading[/red], True)
str = myfile.ReadAll
Wscript.Echo str
myfile.Close
Hope this helps


HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
make sense and works now

a little bit closer...

tx
 
Glad to help, thanks for the star [smile]

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Hi,

I'm now able to get the information I need (using skipline and skip methods) - I now need to send this info via email. I have outlook on the machine and it is able to send and receive email. I don't have to send through outlook if there is another easier way.

Is this complicated?

Tx again
Grd
 
No, thankfully it's not complicated [smile]

faq329-6717 contains an example of sending e-mails from VBScript.

Hope this helps

HarleyQuinn
---------------------------------
The most overlooked advantage to owning a computer is that if they foul up there's no law against wacking them around a little. - Joe Martin

Get the most out of Tek-Tips, read FAQ222-2244 before posting.
 
Thanks

I used the link and got an email message. I now have to test it on the real machine

Thanks again
Grd
 
Here is another email example using blat:

On Error Resume Next
emaillist="someone@someone.com,wiley.coyote@acme.com"

function CheckFile()
On Error Resume Next
set fso=WScript.CreateObject("Scripting.FileSystemObject")
If (fso.FileExists("\\ggnu\share\t.txt")) Then
CheckFile="yes"
Else
CheckFile="no"
End If
End Function

Sub send_alert(subj,msg)
On Error Resume Next
Set shell = WScript.CreateObject("WScript.Shell")
shell.Run "blat -to " & emaillist & " -subject """ & subj & """ -body """ & msg & "", 1, True
End Sub

Set fso=Wscript.CreateOBject("Scripting.FileSystemObject")
Set net=Wscript.CreateObject("WScript.Network")
Set shell=WScript.CreateObject("WScript.Shell")
If fso.FolderExists("\\ggnu\share") Then
emailit=CheckFile()
If emailit="yes" Then
subj="Upload Failure"
msg="\\ggnu\share\t.txt"
Call send_alert(subj,msg)
End If
Else
WScript.Echo "Folder does not exist"
End If
set fso=nothing
set net=nothing
set shell=nothing
WScript.Quit
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top