Sending a mail from shell scripting

2.5k Views Asked by At

I write a script for scheduling backup process .In that script i want to trigger a mail to the corresponding user and admin user as " Backup completed successfully for the $username at $date $time.what can i do .then which packages i need to install ...? please help me...!

#!/bin/bash

echo "---welcome to File Backup process---" 

whoami

#echo "--Please enter your public Key name--"
#read username

username=$(whoami)

echo "username:$username"

rsync -avz --delete --exclude=".bash_history" --exclude=".bash_logout" --exclude=".bashrc" --exclude=".cache*" --exclude=".profile" --exclude=".ssh*" /home/$username/ $username@server:/home/$username/

echo "--Backup completed--"
1

There are 1 best solutions below

0
On

. You can use mailx and mail with attachmet file.

echo 'Content' | mail -aFrom:[email protected] -s 'Subject' -A attachment [email protected]

(echo 'Content';uuencode filename file-attachment-path) | mailx -s subject [email protected]