Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multiple line output from command line in SMTP

Posted on 2010-09-06
16
Medium Priority
?
428 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 498 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
Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

 
LVL 43

Assisted Solution

by:Steve Knight
Steve Knight earned 501 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 58

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 58

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 58

Accepted Solution

by:
Bill Prew earned 501 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 learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

636 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