Tony Paterson
2004-08-05 18:28:53 UTC
Hi,
After a very nasty scare with our JetStream bill we have become a bit paranoid about our usage.
As a simple mechanism, and I emphasise simple, we run Andrews "Traffic Usage Checker" each hour and twice a day mail the tail of the log to our selves. Gives us a "in your face" kind of monitoring. Oh and thanks again Andrew for your great tool !
The path I chose was to find a simple command line mail program, I found "postmail", and a Windows port of "tail".This was combined with a batch file that runs twice daily.
Just in case it is of interest to others I am sending it to the list. I have added it inline because I don't like sending attachments to mailing lists.
Anyway there it is.
Cheers
Yours Tony Paterson
================ send_jetstream_stat.bat ===================
echo off
REM
REM JetStream Usage Meter Email Script
REM
REm Author: Tony Pateson (***@cantabrian.co.nz)
REM
REM The following script is designed to email the end,
REM or "tail" of the log file created by "Traffic usage checker"
REM by Andrew Connell and available at:
REM
REM http://4g.virtual.net.nz/tuc/
REM
REM This script also uses a command line emailing
REM program called "PostMail".
REM
REM
REM
REM Finally we use a Windows version of the Unix "tail"
REM program to display the last x lines of the log. There
REM is more than one version of "Tail for Windows", the version
REM I use is available as "tail_10.zip" and is 57KB. If you can't
REM find this one you need to find one that will allow you to
REM display the last x lines in a file. This version of
REM "tail" responds to command lines like:
REM
REM tail 10 usage.log
REM
REM
REM
REM Setup
REM =====
REM Place this file, tail.exe and PostMail.exe in a suitable directory, I
REM used "c:\scripts". I called this file "send_jetstream_stat.bat".
REM
REM Once you know everything is working setup a scheduled task to
REM run the script at intervals that suit you.
REM
REM
REM Remember:
REM The usage tool will only create a log file if you first create
REM a file called "usage.log" in the same directory as the usage
REM program
REM
REM
REM *********************************************************************
REM *
REM * User Configuration
REM *
REM * The following variables that you will most likely
REM * need to customise for you environment.
REM *
REM * LOGDIR - The directory where your usage log file lives
REM * LOGNAME - Name of your log file, this should be "usage.log"
REM * EMAILADDRESS - The email address of the recipients of the log. If
REM * more than one address separate addresses by a blank space.
REM * EMAILFROM - The Senders email address
REM * EMAILFROMNAME - The Senders full name
REM * EMAILSUBJECT - The subject for the emails
REM * NUMLINES - How many lines, from the BOTTOM of the log file
REM * that you want included in the email. Remember
REM * log entries are added at the END of the log file!
REM * SMTPSVR - The address/name of your smtp server
REM *
SET LOGDIR=C:\PROGRA~1\TRAFFI~1\WELLIN~1
SET LOGNAME=usage.log
SET EMAILADDRESS=***@cantabrian.co.nz ***@salestech.co.nz
SET EMAILSUBJECT=JetStream Usage - Wellington
SET NUMLINES=30
SET EMAILLOG=JetStreamEmailer.log
SET EMAILFROM=***@salestech.co.nz
SET EMAILFROMNAME=Tony Paterson
SET SMTPSVR=stl550
REM
REM System created variables
REM Do NOT change!
REM
SET TMPLOGNAME=usage_temp.log
SET /a NUMLINES = NUMLINES + 3
REM
REM Log file header
REM
echo . >> %EMAILLOG%
echo . >> %EMAILLOG%
echo Begining Emailing Log >> %EMAILLOG%
REM
REM Determine the date and time to be
REM included in the subject
REM
for /f "Tokens=1" %%i in ('time /t') do set tm=%%i
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%l%%k%%j
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i_%%j/%%k/%%l
SET EMAILDATE= %dt% [%tm%]
echo %EMAILDATE% >> %EMAILLOG%
REM
REM Create temp log file
REM
Echo Copying log file... >> %EMAILLOG%
copy %LOGDIR%\%LOGNAME% %LOGNAME%
echo . >> %LOGNAME%
echo ............... End of Log ............... >> %LOGNAME%
echo . >> %LOGNAME%
Echo Tailing log file... >> %EMAILLOG%
tail %NUMLINES% %LOGNAME% > %TMPLOGNAME%
SET CMDLINE=postmail -S"%EMAILSUBJECT% for %EMAILDATE%" -f%EMAILFROM% -F"%EMAILFROMNAME%" -H%SMTPSVR% %EMAILADDRESS%
Echo %CMDLINE%... >> %EMAILLOG%
REM
REM Send the log
%CMDLINE% < %TMPLOGNAME%
REM
REM Tidy up by deleting temp files
REM
del /Q %TMPLOGNAME%
del /Q %LOGNAME%
After a very nasty scare with our JetStream bill we have become a bit paranoid about our usage.
As a simple mechanism, and I emphasise simple, we run Andrews "Traffic Usage Checker" each hour and twice a day mail the tail of the log to our selves. Gives us a "in your face" kind of monitoring. Oh and thanks again Andrew for your great tool !
The path I chose was to find a simple command line mail program, I found "postmail", and a Windows port of "tail".This was combined with a batch file that runs twice daily.
Just in case it is of interest to others I am sending it to the list. I have added it inline because I don't like sending attachments to mailing lists.
Anyway there it is.
Cheers
Yours Tony Paterson
================ send_jetstream_stat.bat ===================
echo off
REM
REM JetStream Usage Meter Email Script
REM
REm Author: Tony Pateson (***@cantabrian.co.nz)
REM
REM The following script is designed to email the end,
REM or "tail" of the log file created by "Traffic usage checker"
REM by Andrew Connell and available at:
REM
REM http://4g.virtual.net.nz/tuc/
REM
REM This script also uses a command line emailing
REM program called "PostMail".
REM
REM
REM
REM Finally we use a Windows version of the Unix "tail"
REM program to display the last x lines of the log. There
REM is more than one version of "Tail for Windows", the version
REM I use is available as "tail_10.zip" and is 57KB. If you can't
REM find this one you need to find one that will allow you to
REM display the last x lines in a file. This version of
REM "tail" responds to command lines like:
REM
REM tail 10 usage.log
REM
REM
REM
REM Setup
REM =====
REM Place this file, tail.exe and PostMail.exe in a suitable directory, I
REM used "c:\scripts". I called this file "send_jetstream_stat.bat".
REM
REM Once you know everything is working setup a scheduled task to
REM run the script at intervals that suit you.
REM
REM
REM Remember:
REM The usage tool will only create a log file if you first create
REM a file called "usage.log" in the same directory as the usage
REM program
REM
REM
REM *********************************************************************
REM *
REM * User Configuration
REM *
REM * The following variables that you will most likely
REM * need to customise for you environment.
REM *
REM * LOGDIR - The directory where your usage log file lives
REM * LOGNAME - Name of your log file, this should be "usage.log"
REM * EMAILADDRESS - The email address of the recipients of the log. If
REM * more than one address separate addresses by a blank space.
REM * EMAILFROM - The Senders email address
REM * EMAILFROMNAME - The Senders full name
REM * EMAILSUBJECT - The subject for the emails
REM * NUMLINES - How many lines, from the BOTTOM of the log file
REM * that you want included in the email. Remember
REM * log entries are added at the END of the log file!
REM * SMTPSVR - The address/name of your smtp server
REM *
SET LOGDIR=C:\PROGRA~1\TRAFFI~1\WELLIN~1
SET LOGNAME=usage.log
SET EMAILADDRESS=***@cantabrian.co.nz ***@salestech.co.nz
SET EMAILSUBJECT=JetStream Usage - Wellington
SET NUMLINES=30
SET EMAILLOG=JetStreamEmailer.log
SET EMAILFROM=***@salestech.co.nz
SET EMAILFROMNAME=Tony Paterson
SET SMTPSVR=stl550
REM
REM System created variables
REM Do NOT change!
REM
SET TMPLOGNAME=usage_temp.log
SET /a NUMLINES = NUMLINES + 3
REM
REM Log file header
REM
echo . >> %EMAILLOG%
echo . >> %EMAILLOG%
echo Begining Emailing Log >> %EMAILLOG%
REM
REM Determine the date and time to be
REM included in the subject
REM
for /f "Tokens=1" %%i in ('time /t') do set tm=%%i
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%l%%k%%j
for /f "Tokens=1-4 Delims=/ " %%i in ('date /t') do set dt=%%i_%%j/%%k/%%l
SET EMAILDATE= %dt% [%tm%]
echo %EMAILDATE% >> %EMAILLOG%
REM
REM Create temp log file
REM
Echo Copying log file... >> %EMAILLOG%
copy %LOGDIR%\%LOGNAME% %LOGNAME%
echo . >> %LOGNAME%
echo ............... End of Log ............... >> %LOGNAME%
echo . >> %LOGNAME%
Echo Tailing log file... >> %EMAILLOG%
tail %NUMLINES% %LOGNAME% > %TMPLOGNAME%
SET CMDLINE=postmail -S"%EMAILSUBJECT% for %EMAILDATE%" -f%EMAILFROM% -F"%EMAILFROMNAME%" -H%SMTPSVR% %EMAILADDRESS%
Echo %CMDLINE%... >> %EMAILLOG%
REM
REM Send the log
%CMDLINE% < %TMPLOGNAME%
REM
REM Tidy up by deleting temp files
REM
del /Q %TMPLOGNAME%
del /Q %LOGNAME%
--
This message is part of the NZ ADSL mailing list.
see http://unixathome.org/adsl/ for archives, FAQ,
and various documents.
To unsubscribe: send mail to ***@lists.unixathome.org
with "unsubscribe adsl" in the body of the message
This message is part of the NZ ADSL mailing list.
see http://unixathome.org/adsl/ for archives, FAQ,
and various documents.
To unsubscribe: send mail to ***@lists.unixathome.org
with "unsubscribe adsl" in the body of the message