cancel
Showing results for 
Search instead for 
Did you mean: 

Windows script for long running jobs

Ranjit1
Level 4

**** Moved to new post from https://vox.veritas.com/t5/NetBackup/Long-running-or-Hung-jobs-script/m-p/289306  ****

Hi @Jacob,

 can you please share the same script for windows please, actually we have windows server fro master and media( only 1 master & 1 media)

12 REPLIES 12

Tape_Archived
Moderator
Moderator
   VIP   

Convert the script to powershell (I am trying it on this Smiley Wink ) or use cygwin to run this script.

sclind
Moderator
Moderator
   VIP   

OpsCenter can give you this also

Hi Tape_Archived,

 

Thnaks for the response

 

Can you please share me the powershell script actually i am not good in powershell

 

 

Thaank you in advance

Hi, 

 

I tried to modify in powershell, Can you please confirm will it work or not 

 


$date = Get-Date -Format "yyyy-MM-dd"

$rpt_file ="c:\temp\backup_rpt_"+$date+".csv"


ALARM_TRESHOLD=84000
RUNTIME=0
bpdbjobs -most_columns | awk -F "," ' $3 ~ /^1$/ { print } ' | awk -F "," ' $2 ~ /^0$/ { print } ' | awk -F "," '{ print $1, $3, $6, $7, $10 }' | while read PID STATE SCHEDULE CLIENT RUNTIME
do
if [ RUNTIME -gt ALARM_TRESHOLD ]
then
echo "Job ${PID} ${CLIENT} ${SCHEDULE} runtime is ${RUNTIME}. It's exceeded runtime treshold of ${ALARM_TRESHOLD} "
fi
done

# Sending email

set $SMTPport=Port number
set $Mailto=xyz.com
set $Mailfrom=abc.com
set $Mailsubject="Long Backup Report"
set $AttachmentDir=" c:\temp"
set $AttachmentFile_UK=$rpt_file


Send-MailMessage -SmtpServer "X.X.X.X" -From "abc.com" -To "xyz.com" -Attachments $rpt_file -Subject "Long Backup Report"

 

Hi Tape_Archived,

 

Thnaks for the response

 

Can you please share me the powershell script actually i am not good in powershell

 

 

Thaank you in advance

Tape_Archived
Moderator
Moderator
   VIP   

I didn't try translating this script to powershell. I may try but it will take some time. I will update when I am ready.

 

Thank you

 

Hi Tape_Archived,

 

Any luck, actually i have to implement this in my environment ASAP 

@Tape_Archivedyou chance to convert this to powershell ?

sdo
Moderator
Moderator
Partner    VIP    Certified

@Ranjit1 I might try my hand at this...

sdo
Moderator
Moderator
Partner    VIP    Certified

I'll let you work out how to send an email from PowerShell...

...and I have also tried to give you a simple "jacket / header" script for your own future PowerShell scripts... 

###################################################################################################################
# Vers    Date          Who   Description
# ----    ----          ---   -----------
# v0.01   08-Jan-2019   sdo   Simple script to list long running backup jobs.
###################################################################################################################
# Assumptions
# -----------
# 1) That the Windows system path has been modified to include the folder paths for NetBackup commands.
# 2) That this script will be run on a Master Server, or on a Media Server that is a Server of a Master Server.
#
# Abstract
# --------
# Creates a simple report file of long running jobs.
###################################################################################################################
 
 
 
###################################################################################################################
# Script behaviour settings...
#
 
$ErrorActionPreference = "Stop"
 
 
 
###################################################################################################################
# Functions...
#
 
Function Log( $myText ) {
  If ( $myText -eq $Null ) {
    Write-Host ""
  } Else {
    Write-Host $myText
  }
 
  If ( $myScriptLog -ne "" ) {
    If ( $myText -eq $Null ) {
      Add-Content -Path $myScriptLog -Value ""
    } Else {
      Add-Content -Path $myScriptLog -Value $myText
    }
  }
}
 
 
Function Test-IsAdmin {
  Try {
    $myIdentity = [Security.Principal.WindowsIdentity]::GetCurrent()
    $myPrincipal = New-Object Security.Principal.WindowsPrincipal -ArgumentList $myIdentity
    Return $myPrincipal.IsInRole( [Security.Principal.WindowsBuiltInRole]::Administrator )
  } Catch {
    Throw "...failed to determine if the current user is an admin, error '{0}'..." -f $_
  }
}
 
 
 
 
###################################################################################################################
# Display script name and location...
#
 
$myScriptSpec = [System.IO.FileInfo]$PSCommandPath
$myScriptPath = $myScriptSpec.Directory
$myScriptName = $myScriptSpec.BaseName
 
$myUsername   = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
 
$myComputerDomain = ( Get-WmiObject Win32_ComputerSystem ).Domain
$myComputername   = ( Get-WmiObject Win32_ComputerSystem ).Name
 
$myScriptDat = Join-Path $myScriptPath "$myScriptName.dat"
$myScriptLog = Join-Path $myScriptPath "$myScriptName.log"
$myScriptTmp = Join-Path $myScriptPath "$myScriptName.tmp"
$myScriptTxt = Join-Path $myScriptPath "$myScriptName.txt"
 
If ( Test-Path $myScriptDat ) { Remove-Item $myScriptDat }
If ( Test-Path $myScriptLog ) { Remove-Item $myScriptLog }
If ( Test-Path $myScriptTmp ) { Remove-Item $myScriptTmp }
If ( Test-Path $myScriptTxt ) { Remove-Item $myScriptTxt }
 
 
Log ""
Log "...script spec:       $myScriptSpec"
Log "...script path:       $myScriptPath"
Log "...script name:       $myScriptName"
Log ""
Log "...user:              $myUsername"
Log "...computer name:     $myComputerName"
Log "...computer domain:   $myComputerDomain"
Log ""
Log ""
 
 
If ( -not ( Test-IsAdmin ) ) {
  Log "...script must be run as administrator, script aborting..."
  Exit 2
}
 
 
 
###################################################################################################################
# Once more unto the breach, dear friends...
#
 
$myThreshold = 86400
 
bpdbjobs -most_columns -file $myScriptDat
$myStatus = $LastExitCode
If ( $myStatus -ne 0 ) {
  Log "...failed to collect job data, status '$myStatus'..."
  Exit $myStatus
}
 
 
Get-Content $myScriptDat | ForEach-Object {
  $myData      = $_ -Split ","
  $jobID       = $myData[0]
  $jobType     = $myData[1]
  $jobState    = $myData[2]
  $jobSchedule = $myData[5]
  $jobClient   = $myData[6]
  $jobRunTime  = [int]$myData[9]
 
  If ( $jobType -eq "0" ) {
    If ( $jobRunTime -gt $myThreshold ) {
      Log "job $jobID $jobClient $jobSchedule runtime is $jobRuntime"
 
      Add-Content -Path $myScriptTxt -Value "long job $jobID $jobClient $jobSchedule runtime is $jobRuntime"
    }
  }
}
 
 
Exit 0

 

@sdoThank you very much, i will try this