Solved

Multiple line output from command line in SMTP

Posted on 2010-09-06
16
423 Views
Last Modified: 2012-05-10
I am not sure how to word this.
i am using a command line SMTP client to send a log file as a email. the utility is bmail.
http://www.beyondlogic.org/solutions/cmdlinemail/cmdlinemail.htm

bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -b "Start time:%StartTime% End Time:%EndTime%" -m "%Logfile%"

The part:  -b "Start time:%StartTime% End Time:%EndTime%"
The output it is giving is Start time:16:27:18.77 End Time:16:28:03

I want it to be:
Start time:16:27:18.77
End Time:16:28:03

How do i get it to return to the next line between the 2 parts?
0
Comment
Question by:tsukraw
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 3
  • 3
  • +1
16 Comments
 
LVL 21

Assisted Solution

by:AmazingTech
AmazingTech earned 166 total points
ID: 33615393
I don't think you can with the -b parameter. Perhaps you can create a text file and then use the -d.

echo Start time:%StartTime%>Body.txt
echo End Time:%EndTime%>>Body.txt

bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -d Body.txt  -m "%Logfile%"
0
 

Author Comment

by:tsukraw
ID: 33615400
-d is debug?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616383
I think he means -m,

Steve
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 167 total points
ID: 33616406
And I don't know what happened to the code segment I attached there, typing in directly this time... just creates a new file in temp with your log details then the original log file.

Steve

set log="%temp%\logfile.txt"
echo Start time:%StartTime%>%log%
echo End Time:%EndTime%>>%log%
echo. >> %log%
type %logile% >%log%
bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%" -d Body.txt  -m "%Log%"
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616409
Sorry forgot to change the last time second time around:
set log="%temp%\logfile.txt"
echo Start time:%StartTime%>%log%
echo End Time:%EndTime%>>%log%
echo. >> %log%
type %logile% >%log%
bmail -s localhost -t %%A -f backup@domain.local -h -a "Backup Report - %Date%"  -m %Log%
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616417
I blame EE not accepting it first time around .... try changing

type %logile% >%log%


to
type %logfile% >>%log%

too!

Steve
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 33616687
I believe the piece that Tucker may not have shared is that the log file he is already attaching is generated out of a utility program, so that file needs to be attached, and can not be pre-pended to.  In addition to having that file attached, he wants a multiline body.

It doesn't look like bmail accepts multiple -m files so not sure how to solve this?

~bp
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33616707
That is why I was (trying) to suggest creating the new text and then Appending the old file to the end and attaching that one instead.

Personally I tend to use blat.exe for mailing though have had to use bmail.exe for some people and can't think of another way at the moment short of using one of the MIME body encoding progs to make a body and attach it.

Steve
0
 
LVL 55

Expert Comment

by:Bill Prew
ID: 33616740
Gotcha Steve.

~bp
0
 

Author Comment

by:tsukraw
ID: 33616782
So overall the solution would be to have the script create a new log file with the content I want and join the utilities output log int it?  
outputting the content I want to a file is simple enough but how do I join the other file into it?
0
 
LVL 55

Accepted Solution

by:
Bill Prew earned 167 total points
ID: 33616905
Tucker,

I think the resultant script would look like this.

Notice that we capture the output of the backup to a temporary log file (log.txt) and then after writing the begin and end header lines to the real log file we add on the output of the backup command.  Then that is what we email.

Make sense?

~bp
@echo off
set Day=%DATE:~10,4%_%DATE:~4,2%_%DATE:~7,2%
set CurrentDir=%~dp0
if "%CurrentDir:~-1%"=="\" set CurrentDir=%CurrentDir:~0,-1%
set Logfile=%CurrentDir%\BackupLogs\G-Drive-%Day%.txt
 
echo Start Time:%TIME%>"%Logfile%"
 
wbadmin start backup -backupTarget:G: -include:F: -quiet > "%TEMP%\log.txt"
 
echo End Time:%TIME%>>"%Logfile%"
echo.>>"%Logfile%"
type "%TEMP%\log.txt" >>"%Logfile%"
 
for /F "usebackq tokens=*" %%A in ("emailaddy.txt") do (
  bmail -s localhost -t %%A -f backup@severname -h -a "Backup Report - %Date%" -m "%Logfile%"
)

Open in new window

0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 33617154
Didn't know this was a follow up Bill.  

See post 33616409 / 33616417 above :-)

Steve
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 33629303
Sorry, I was replying on my iPhone so the -d should have been the -m but also include the log file like how dragon-it explained it.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 34080713
Accept billprew http:#33616905.
Assist dragon-it http:#33616409
and AmazingTech http:#33615393
0
 

Author Closing Comment

by:tsukraw
ID: 34089452
Really no solution with this app.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question