So I found this script from an older forum (veeam-agents-for-linux-mac-aix-solaris- ... 36789.html.
So the code is:
Code: Select all
#!/bin/bash
# Script to run vm_backup and email job status
JOBNAME=vm_backup
SCRIPT_DIR=/etc/veeam/scripts
LOG_DIR=/var/log/veeam/Backup/$JOBNAME
JOB_INFO=`veeamconfig job info --name $JOBNAME`
#start backup job
veeamconfig job start --name $JOBNAME 1> /etc/veeam/scripts/$JOBNAME.tmp 2> /etc/veeam/scripts/$JOBNAME.err
SESSION_ID=`grep ID $SCRIPT_DIR/$JOBNAME.tmp | awk  '{print $3}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
SESSION_LOG_DIR=`grep log $SCRIPT_DIR/$JOBNAME.tmp | awk  '{print $4}' | sed 's/\[//' | sed 's/\]//' | sed 's/\.//'`
LOGFILE=$SESSION_LOG_DIR/Job.log
SESSION_INFO=`veeamconfig session info --id $SESSION_ID | grep -v UUID`
# check if another job is running
if [ -s $JOBNAME.err ]
then
     ERROR_MSG=`grep Error $SCRIPT_DIR/$JOBNAME.err`
     echo "$ERROR_MSG" | mailx -s "VAL Job $JOBNAME Error" -r VeeamLinuxAgent@email.local  recipient@email.com
fi
#check if job is running
until [ -z `pgrep veeamjobman` ]
do
    echo "job is running" > /dev/null
done
#check and set the exit status of the job
STATUS=`veeamconfig session info --id $SESSION_ID | grep State | awk  '{print $2}'`
if [ $STATUS = 'Warning' ]
then
     WARN_MSG=`veeamconfig session log --id $SESSION_ID | grep warn | awk '{print $6,$7,$8,$9}'`
     echo -e "Job $JOBNAME Successful with following $STATUS:\n\n$WARN_MSG\n\nJOB INFO:\n$JOB_INFO" | mailx -s "VAL Job $JOBNAME $STATUS" -r VeeamLinuxAgent@email.local  recipient@email.com
fi
if [ $STATUS = 'Failed' ]
then
     echo -e "Job $JOBNAME $STATUS. See attached logfile for error details.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "VAL Job $JOBNAME $STATUS" -a $LOGFILE -r VeeamLinuxAgent@email.local  recipient@email.com
fi
if [ $STATUS = 'Success' ]
then
     echo -e "Job $JOBNAME $STATUS.\n\nJOB INFO:\n$JOB_INFO" | mailx -s "VAL Job $JOBNAME $STATUS" -r VeeamLinuxAgent@labinf.local davide.depaoli@labinf.it
fi
rm -f $SCRIPT_DIR/$JOBNAME.tmp $SCRIPT_DIR/$JOBNAME.errScript is located in /etc/veeam/scripts/vm_backup Do I have to change anything about the script's name?
I created a folder /var/log/veeam/Backup
My problem is that I always have to type sudo before every command so this script won't work for me, I'll get "No permission" error.
1> and 2> at the start, are these 2 files created automatically?
How should I change the code to work with sudo before every command?
Thanks