Solved

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

Posted on 2014-03-06
6
1,112 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 19

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now