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
Solved

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

Posted on 2014-03-06
6
1,167 Views
Last Modified: 2014-03-12
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
0
Comment
Question by:michalek19
  • 2
  • 2
6 Comments
 
LVL 20

Expert Comment

by:marsilies
ID: 39910783
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
 

Author Comment

by:michalek19
ID: 39911170
Do  you have different example that will show me how the script looks like?
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 200 total points
ID: 39914699
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
 

Author Comment

by:michalek19
ID: 39923950
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
 
LVL 43

Expert Comment

by:Steve Knight
ID: 39924139
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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Synchronize a new Active Directory domain with an existing Office 365 tenant
This article will help you understand what HashTables are and how to use them in PowerShell.

856 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