muquit / mailsend

A program to send mail via SMTP from command line
Other
294 stars 68 forks source link

Including last n lines of code in body of email #84

Open pthalodezin opened 8 years ago

pthalodezin commented 8 years ago

First off, this little program works perfectly for what I need. Maybe I am a little out of practice with DOS, but is there a way to include the last "n" lines of code/calls from DOS in the body of the email. I have a command with debug on, but there are times when I am gone for hours and the only part I want is this log and I want it in the email so I can deal with it when I am away, rather than waiting to run the error logs when I return.

Any help would be appreciated. Apologies if this should have been obvious.

ghost commented 8 years ago

pthalodezin, you can try to use solution from http://stackoverflow.com/questions/523181/cmd-exe-batch-script-to-display-last-10-lines-from-a-txt-file:

@echo OFF
::
::
::
set DEBUGLOG=debug.log
set LINESNUMBERTOSHOW=10
set msg-body=debug-last-10-lines.log
set LINES=0
for /f "delims==" %%I in (%DEBUGLOG%) do (set /a LINES=LINES+1)
::
set /a LINES=LINES-%LINESNUMBERTOSHOW%
more +%LINES% %DEBUGLOG% >%msg-body%
::
::
::pause
::

and you can set body from file in %msg-body% variable:

-msg-body "%msg-body%"