#!/bin/bash MYJOBNAME="BackupJob" EMAILTO="myemail@domain.com" EMAILFROM="myemail@domain.com" #start the veeam job sudo veeamconfig job start --name $MYJOBNAME > /home/ubuntu/sessionid #get sessionid from return text SESSID=$( grep -r "Session ID" /home/ubuntu/sessionid | cut -d " " -f3 ) SESSID=$( echo "${SESSID:1:${#SESSID}-3}") echo "Job has started - Session: $SESSID" #get current state (running/failed/success) STAT=$( sudo veeamconfig session info --id $SESSID | grep "State:" | cut -d ":" -f2 ) #wait for job to not be running while [ "$STAT" == " Running" ] do echo "Job still running..." STAT=$( sudo veeamconfig session info --id $SESSID | grep "State:" | cut -d ":" -f2 ) sleep 5 done echo "Job has completed in some sort of fashion - now what to do....." #get some information on the session veeamconfig session info --id $SESSID > /home/ubuntu/sessioninfo veeamconfig session log --id $SESSID > /home/ubuntu/sessionlog #extract some variables for email. BACKUP=$( cat /home/ubuntu/sessionlog | grep -o "Backed up.*" ) STARTDATE=$( cat sessioninfo | grep "Start time:" | sed 's/\sStart time:\s/\ /g' | cut -f2 | awk '{print $1}' ) STARTTIME=$( cat sessioninfo | grep "Start time:" | sed 's/\sStart time:\s/\ /g' | cut -f2 | awk '{print $2}' ) ENDDATE=$( cat sessioninfo | grep "End time:" | sed 's/\sEnd time:\s/\ /g' | cut -f2 | awk '{print $1}' ) ENDTIME=$( cat sessioninfo | grep "End time:" | sed 's/\sEnd time:\s/\ /g' | cut -f2 | awk '{print $2}' ) JOBNAME=$( cat sessioninfo | grep "Job name:" | sed 's/\sJob name:\s/\ /g' | cut -f2 | awk '{print $1}' ) #build email echo "From: $EMAILTO To: $EMAILFROM Subject: VAL Job ($JOBNAME) - $STAT MIME-Version: 1.0 Content-Type: text/html
" > /home/ubuntu/email.htm echo "Veeam Agent for Linux job ($JOBNAME) completed with a status of $STAT | |
Start Time: | $STARTDATE - $STARTTIME |
End Time: | $ENDDATE - $ENDTIME |
$BACKUP |