/build/static/layout/Breadcrumb_cap_w.png

Check text in a file

Hi,
I would like to know how to search a specified text in a file and send mail if it found such text.

Actually we have log files in our application, when something wrong occurs it will have errors logged into that logfile.
It will be great to have a script to check the errors we mention in that log and send mail to us.

Share your thoughts to achieve this.

0 Comments   [ + ] Show comments

Answers (10)

Posted by: airwolf 14 years ago
Red Belt
0
You could write something like this in VBS or AutoIt fairly easily. Try doing some Googling, I'm sure you can find something that already exists to do this.
Posted by: nokiak810 14 years ago
Senior Yellow Belt
0
Airwolf,

Thanks for the comments. I have googled but couldn't get my requirement so i have posted here and i am sure that some one will help. If you have some ideas please share.
Posted by: airwolf 14 years ago
Red Belt
0
http://www.google.com/search?hl=en&q=search+text+file+vbs&aq=f&oq=&aqi=
Posted by: nokiak810 14 years ago
Senior Yellow Belt
0
thanks for the help...
Posted by: airwolf 14 years ago
Red Belt
0
The purpose of this forum is to assist those who are having issues with scripting. This is not a request forum to ask someone to write a script for you. I will gladly help those who help themselves, but this is a very common thing you are looking for - and you can make a few minor modifications to existing scripts found via Google to accomplish your goal.
Posted by: UJS 14 years ago
Yellow Belt
0
ORIGINAL: nokiak810


Hi,
I would like to know how to search a specified text in a file and send mail if it found such text.

Actually we have log files in our application, when something wrong occurs it will have errors logged into that logfile.
It will be great to have a script to check the errors we mention in that log and send mail to us.

Share your thoughts to achieve this.




Because I'm feeling nice

Save the code as notify.bat or some such. Set the variables you need


::Download and install Blat
::http://sourceforge.net/projects/blat/files/
::create a tools folder
SET tools=c:\tools_folder_location
::copy blat.exe, blat.dll, and blat.lib to the tool folder location
::Install blat and point to an SMTP server
::change IP to your SMTP server
::the email address is whatever account you want the email to come from
::the 5 is number of retries
%tools%\blat -install 10.0.0.254 admin@emailserver.com 5 - - -
::Set your email address you want the report sent to
SET email=admin@mycompany.com
::Set the name of the file you want to look in, make sure there are no spaces
SET file.name=c:\nameoffile.txt
::Set the text string you want to look for. This can have spaces and is not case sensitive
SET txt.string=email me when you find this error
::reset count
ECHO 0>%temp%\count.txt
::actual check for txt in the file and put number of times the txt is found into a txt file
FIND /I /C "%txt.string%" %file.name%>%temp%\count.txt
::Set the count to 0
SET count=0
::Set count to however many txt.strings were found in the file
FOR /F %%I in (%temp%\count.txt) DO SET count=%%I
IF %count% GTR 0 ECHO %date%-%time% - Found %count% copies of %txt.string% in %file.name%>%temp%\report.txt
::email report
IF %count% GTR 0 %tools%\blat %temp%\report.txt -to %email% -subject "%date% - %time% - %txt.string% error found"
Posted by: sunny07 14 years ago
Senior Yellow Belt
0
the filesystemobject provides you an option to read the content of file, so read the content and store in string variable and then using Instr() function you can find the required text and if the condition satisfies write a command to send mail.
Posted by: nokiak810 14 years ago
Senior Yellow Belt
0
ORIGINAL: UJS


ORIGINAL: nokiak810


Hi,
I would like to know how to search a specified text in a file and send mail if it found such text.

Actually we have log files in our application, when something wrong occurs it will have errors logged into that logfile.
It will be great to have a script to check the errors we mention in that log and send mail to us.

Share your thoughts to achieve this.




Because I'm feeling nice

Save the code as notify.bat or some such. Set the variables you need


::Download and install Blat
::http://sourceforge.net/projects/blat/files/
::create a tools folder
SET tools=c:\tools_folder_location
::copy blat.exe, blat.dll, and blat.lib to the tool folder location
::Install blat and point to an SMTP server
::change IP to your SMTP server
::the email address is whatever account you want the email to come from
::the 5 is number of retries
%tools%\blat -install 10.0.0.254 [email=admin@emailserver.com]admin@emailserver.com[/email] 5 - - -
::Set your email address you want the report sent to
SET email=admin@mycompany.com
::Set the name of the file you want to look in, make sure there are no spaces
SET file.name=c:\nameoffile.txt
::Set the text string you want to look for. This can have spaces and is not case sensitive
SET txt.string=email me when you find this error
::reset count
ECHO 0>%temp%\count.txt
::actual check for txt in the file and put number of times the txt is found into a txt file
FIND /I /C "%txt.string%" %file.name%>%temp%\count.txt
::Set the count to 0
SET count=0
::Set count to however many txt.strings were found in the file
FOR /F %%I in (%temp%\count.txt) DO SET count=%%I
IF %count% GTR 0 ECHO %date%-%time% - Found %count% copies of %txt.string% in %file.name%>%temp%\report.txt
::email report
IF %count% GTR 0 %tools%\blat %temp%\report.txt -to %email% -subject "%date% - %time% - %txt.string% error found"



Hi UJS,

Thanks for the script. Please let me know step by step to run the above script. I have saved the text as you said but when i ran it finishes within a second. Let me know in details.

Thanks for the help done.
Posted by: anonymous_9363 14 years ago
Red Belt
0
Describe what you changed in the sample script so that it would run in your environment. I already guessed the answer...
Posted by: nokiak810 14 years ago
Senior Yellow Belt
0
Hi VBScab and others thanks for the support. At last i found the solution. The below script worked for me.


<job>
<runtime>
<description>This script reads the alert log of an Oracle Instance</description>
<named
name = "log"
helpstring = "Alert.log to read"
type = "string"
required = "true"
/>
<example>Example: ReadAlert.vb.wsf /log:"c:\oracle\10.1.0\admin\orcl\bdump\alert_orcl.log"</example>
</runtime>
<script language="VBScript">

If WScript.Arguments.Count <> 1 Then
WScript.Arguments.ShowUsage
WScript.Quit
End If

ReadAlert (Wscript.Arguments.Named.Item("log"))


Sub ReadAlert(alertlog)
Dim fso, stream, line, errarray
Const ForReading = 1
' get a handle on the file system
Set fso = CreateObject("Scripting.FileSystemObject")
' try opening the file
Set stream = fso.OpenTextFile(alertlog, ForReading)
' Read the contents of the alert log
do while stream.AtEndOfStream = False
line = stream.ReadLine
if instr(1,line,"ORA-",1) = 1 then ' found error
errarray = split(line," ",2)
errcode = errArray(0)
errmsg = errArray(1)
Wscript.Echo errcode & " in Alert.log " & vbcrlf & "Further Information: " & errmsg
end if
loop
stream.Close
set stream = Nothing
set fso = Nothing
End Sub

</script>
</job>


Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ