Printbrm.exe - adding log file and e-mail alert to batch file

Hi Again

I am wondering if there is a way to add  log file and e-mail alert to this batch file when the backup is done

@echo off
set BkupDir=C:\temp
set PrintBRM=%windir%\System32\Spool\Tools\PrintBRM

call :DoBackup M-CORP
call :DoBackup PRT-US
call :DoBackup Y-COR
call :DoBackup BO-RNT1

goto :EOF

:DoBackup [printservername]
  if exist "%BkupDir%\%~1.printerExport" ren "%BkupDir%\%~1.printerExport" "*.bak"
  %PrintBRM% -b -s \\%~1 -f %BkupDir%\%~1.printerExport -O FORCE && (
    if exist "%BkupDir%\%~1.bak" del "%BkupDir%\%~1.bak
  ) || (
    if exist "%BkupDir%\%~1.bak" ren "%BkupDir%\%~1.bak" "*.printerExport"
  )
  goto :EOF

Open in new window

Thx, Michal
michalek19Asked:
Who is Participating?
 
Steve KnightIT ConsultancyCommented:
I either use BLAT as has been suggested or a small VBScript, or re-write it to run from VBScript instead, e.g.  my page here: http://scripts.dragon-it.co.uk/links/email-from-batch

This is more than you want there but shows including the email bits using BLAT:

http://scripts.dragon-it.co.uk/links/batch-backup-with-rotation-and-emails


@echo off
set BkupDir=C:\temp
set PrintBRM=%windir%\System32\Spool\Tools\PrintBRM
Set log="C:\temp\log.txt"

REM You should be able to log all output of commands to log file like this
(call :DoBackup M-CORP
call :DoBackup PRT-US
call :DoBackup Y-COR
call :DoBackup BO-RNT1
) > %log% 2>&1

REM Then when complete send it
cscript //nologo c:\temp\sendmail.vbs

goto :EOF

:DoBackup [printservername]
  if exist "%BkupDir%\%~1.printerExport" ren "%BkupDir%\%~1.printerExport" "*.bak"
  %PrintBRM% -b -s \\%~1 -f %BkupDir%\%~1.printerExport -O FORCE && (
    if exist "%BkupDir%\%~1.bak" del "%BkupDir%\%~1.bak
  ) || (
    if exist "%BkupDir%\%~1.bak" ren "%BkupDir%\%~1.bak" "*.printerExport"
  )
  goto :EOF

Open in new window


together with sendmail.vbs:

Const MailServer = "12.34.56.78" ' Mail Server to use for SMTP
Const MailServerPort = "25" ' SMTP Port used at Mail server (25 is default)
Const MailTo = "logs@somedomain.com" ' Who should be notified
Const MailFrom = "logs@somedomain.com" 
subject = "Backup logs for XYZ"
body = "Message to add in body here"

'Send mail to administrator
SendMail MailFrom , MailTo , subject , body, MailServer , MailServerPort 

Sub SendMail(Sender, Recipient, Subject, Message,Server,Port)
  Set objEmail = CreateObject("CDO.Message")
  objEmail.From = Sender
  objEmail.To = Recipient
  objEmail.Subject = Subject 
  objEmail.Textbody = Message
  objEmail.AddAttachment "c:\temp\log.txt"
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = Server
  objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = Port
  objEmail.Configuration.Fields.Update()
  objEmail.Send
End Sub

Open in new window

0
 
marsiliesCommented:
You can pipe the whole batch file to a log with the > switch. For example, if the above batch file is named printbrm.cmd:
printbrm.cmd > printbrm.log
http://www.robvanderwoude.com/battech_redirection.php

The printbrm.exe command itself had problems with piping, which was fixed in Windows 7 and higher:
http://www.minasi.com/forum/topic.asp?TOPIC_ID=32445


As for emailing, you'll need an email client. Blat is a command-line email client tool that you could set up and add to your batch file:
http://sourceforge.net/projects/blat/
http://www.blat.net/syntax/syntax.html

It may also be possible to send an email via the built-in telnet client, but this sounds trickier:
http://community.spiceworks.com/topic/265337-how-to-send-email-from-command-line-in-windows-7


I think it makes the most sense to use two batch files: the original one for running the task, and the 2nd one for piping the output from the first into a log file, then emailing the log file.
0
 
michalek19Author Commented:
Do  you have different example that will show me how the script looks like?
0
 
michalek19Author Commented:
Is it possible to create spread sheet file instead txt file
Also, the result is hard to read. Is it possible to make that output clear to ready

Like for example
Operation mode: backup
Target server: \\PRLTarget file path: \\fs01\printodb\PS-ATL.printerExport.
Queue publish mode:

Print server name:                  

Hostname:                             IP address        Driver      Percentage %
PRINT QUEUES ATL-8155
HPLJAPLJATL
.....
Log-file.txt
0
 
Steve KnightIT ConsultancyCommented:
I'm not familiar with using that export command and any other options you can do with it.  We can always do some processing on the log file after it has been created etc. but apart from making a CSV file to open into Excel that might be your only way to do that.

Steve
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.