PowerShell script exchange
Post Reply
crichardson
Enthusiast
Posts: 39
Liked: never
Joined: Dec 09, 2010 1:25 pm
Full Name: Corey
Contact:

Email on long running job

Post by crichardson »

Every couple of months, typically over a weekend, my Veeam jobs will get stuck at 0%. I have no idea why this happens and Veeam Support has pointed me to this article: http://www.veeam.com/kb1727. The problem is when this happens - on a weekend. I don't find out until Monday (or with Today's case, Tuesday because of the holiday). We're still trying to determine why it's happening.

What I'd like to know is how I could script something simple that will check all the current running jobs to see if they have been running longer than 8 hours. I'll schedule the script to run every hour. If there is a job running longer than 8 hours, I want it to email me with the job name.

Is this possible? Thanks.
veremin
Product Manager
Posts: 20406
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Email on long running job

Post by veremin »

Hi Corey, do you have Veeam ONE deployed? If so, you can use one of its alarms that will notify you, if job exceeds allocated time interval. Thanks.
crichardson
Enthusiast
Posts: 39
Liked: never
Joined: Dec 09, 2010 1:25 pm
Full Name: Corey
Contact:

Re: Email on long running job

Post by crichardson »

v.Eremin wrote:Hi Corey, do you have Veeam ONE deployed? If so, you can use one of its alarms that will notify you, if job exceeds allocated time interval. Thanks.
I do not. I assume that's only available in the full version of Veeam ONE?
veremin
Product Manager
Posts: 20406
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Email on long running job

Post by veremin »

Yes, job duration alarm is shipped in paid version of Veeam ONE. As to PS, you should write something like this:

Code: Select all

$Date = Get-Date
$Jobs = Get-VBRJob | where {$_.Getlaststate() -eq "Working"}
Foreach ($Job in $Jobs){
if (($Date - ($Job.FindLastSession().CreationTime)).hours -ge 8){
$Job | Stop-VBRJob
}
}
Thanks.
crichardson
Enthusiast
Posts: 39
Liked: never
Joined: Dec 09, 2010 1:25 pm
Full Name: Corey
Contact:

Re: Email on long running job

Post by crichardson »

I couldn't figure out how to query for running jobs. It's "working". Thanks!
veremin
Product Manager
Posts: 20406
Liked: 2299 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: Email on long running job

Post by veremin »

And if you want just to have notification, not immediately stop a long running job, then, replace "stopping" part with something that has to with email creation. Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 21 guests