[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1006
  • Last Modified:

Robocopy - Monitor with Email Reporting

I have a server in NY and one in London.
I have set up a folder in NY so when a user drops a file into it, it moves it to a folder on the server in London. I have done this using Robocopy and I am  happy with it.
It is using the MOT switch and is constantly running.

I would like to add some kind of email functionality so that when a file has been sucessfully copied a notification is sent to specified users.

I have managed to do this with a batch file running a single Robocopy instance and calling a PowerShell command after. But as this works by running after robocopy it does not suit my needs. I need it to run after a file has been succesffuly copied

I run this batch file
-----------------------------------------------------
Robocopy "\\NYServer\Folder1" "\\LondonSever\Folder1" /E /Z /MOT:2 /MOVE /R:20"

Powershell.exe C:\Robocopy\Email.ps1
-------------------------------------------------------




This is  Powershell Email.ps1
-------------------------------------------------------
$emailFrom ="user@domain.co.uk"

$emailTo = "user@domain.co.uk"

$subject = "Test"

$body = "New file in folder"

$smtpserver = "smtp.domain.co.uk"

$smtp = new-object Net.Mail.smtpClient($smtpServer)

$smtp.send($emailfrom, $emailTo, $subject, $body)


 I hope this is enough information for you to help me.




0
00831607020
Asked:
00831607020
  • 2
1 Solution
 
larsrohrCommented:
Since robocopy is running continuously with MOT, you never get to the powershell command, of course.

You might try running robocopy with a logging option, e.g.
  Robocopy "\\NYServer\Folder1" "\\LondonSever\Folder1" /E /Z /MOT:2 /MOVE /R:20 /LOG:C:\robolog.txt
(I don't know, though, does robocopy append to the log in this case when run with /MOT, or will it potentially overwrite the log every 2 minutes?)

... and then running a separate continuous Powershell script that monitors C:\robolog.txt for changes/additions, and sends your email when appropriate.
I don't have a specific powershell script to do this, but the file monitoring script discussed on the following page may provide inspiration:
 http://gallery.technet.microsoft.com/ScriptCenter/en-us/ed188912-1a20-4be9-ae4f-8ac46cf2aae4


Depending on how robocopy does logging in /MOT mode, and how successfully a powershell script monitors the logfile, you may want to use /LOG+:C:\robolog.txt  (specify append mode).
0
 
00831607020Author Commented:
Sorry for not  getting back to this.... Holiday, busy, etc, etc.
Thank you for the response, I will aim to get round to trying your suggestion this week.
0
 
00831607020Author Commented:
Sorry I did not respond to this, but other tasks took over and it got left behind.
I hope to revisit this one timem though and will report back if I get an answer.
 
0

Featured Post

Evaluating UTMs? Here's what you need to know!

Evaluating a UTM appliance and vendor can prove to be an overwhelming exercise.  How can you make sure that you're getting the security that your organization needs without breaking the bank? Check out our UTM Buyer's Guide for more information on what you should be looking for!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now