Visit Our UNIX and Linux User Community


Email script when automatic backup is finsihed


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Email script when automatic backup is finsihed
# 1  
Old 10-02-2009
Email script when automatic backup is finsihed

Hello all,

i'm still new to this site and thought i might find some help here Smilie.
lately i performed a script to make an automatic backup of some files in certain directories. the script looks something like this:

Code:
#! /bin/bash

##############VARIABLES

path=/export/home/cassi/Backup
timestamp=`date +%Y%m%d`
host=`hostname`
file_in=$path/files2tar
tarfile=$path/$host-$timestamp-bak.tar

################TAR AND GZIP FILES

data=`cat $file_in`
tar cf $tarfile $data
/usr/bin/gzip $tarfile

With this script the backup of files works fine. This script is also set as a cronjob to be run weekly.

My question is this. I need to find a way to make an automatic email if all files are successfully transfered. is there a way to perform this?

Thanks for reading,

Matthew

Last edited by vgersh99; 10-02-2009 at 10:38 AM.. Reason: code tags, PLEASE!
# 2  
Old 10-02-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums
# 3  
Old 10-02-2009
You can check $? which will have the exit code of each former command (maybe your tar and gzip) with an if/fi instruction for example and then decide to send a mail or not. If $? is > 0 then it might have had some troubles.
# 4  
Old 10-02-2009
Hi Wizard,

Try the following -

Code:
data=`cat $file_in`
tar cf $tarfile $data > /dev/null
res1 = $?
/usr/bin/gzip $tarfile > /dev/null
res2 = $?

if [ $res1 -eq 0 ]  && [ res2 = 0 ]; then
   echo "BackUP & Zip operation successful." > /tmp/mailtext
elif [ $res1 -eq 0 ]; then
   echo "BackUP is successful.  Some issue in Zip operation." > /tmp/mailtext
elif [ $res2 -eq 0]; then
   echo "Backup Failed" > /tmp/mailtext
fi

mailx -s "Backup Result"  <your email id>  < /tmp/mailtext

rm /tmp/mailtext

#Done

# 5  
Old 10-02-2009
Thanks for your reply. Forgive my ignorance, i am still very new to UNIX and scripting. Can you show me such example?

thanks.

---------- Post updated at 08:01 AM ---------- Previous update was at 08:00 AM ----------

Thanks ggs i will try that!

---------- Post updated at 08:22 AM ---------- Previous update was at 08:01 AM ----------

Hi ggs, is there a way to cinfigure mailx? the reason is that the files are stored in this machine which i then need to receive an email on a windows machine.
# 6  
Old 10-02-2009
Check for posts with "uuencode" using the search function of the forum. They will show you how to send mails with files as attachment.

Previous Thread | Next Thread
Test Your Knowledge in Computers #98
Difficulty: Easy
Unix was the first operating system that was written in a high-level programming language (C Language).
True or False?

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Automatic scp Script

I need a script to automatically scp the latest files on DIR1,DIR2 and DIR3 from Source to destination server at same place(DIR1,DIR2 and DIR3) . Further details are: Source Server (192.168.1.5) DIR1 DIR2 DIR3 Destination Server (192.168.1.10) DIR1 DIR2 DIR3 (7 Replies)
Discussion started by: refra
7 Replies

2. Shell Programming and Scripting

Automatic script trigger

Hi, I'm looking for a way to solve the following scenario: A shell should automatically trigger / run when a text file is placed or present at a specific location. My idea - to create a cron / anacron for every minute and inside that i will call a temp script. Temp script will move to my... (9 Replies)
Discussion started by: Gautham
9 Replies

3. Shell Programming and Scripting

Email backup log

Hi, I have a server which appends to two different backup logs, a summary and a full log, I want to write a script which will email out this mornings backup, the problem is that in the log files the date is in the below format: Fri May 31,2013 02:30 the summary log file I can just use... (6 Replies)
Discussion started by: Bdoydie
6 Replies

4. Shell Programming and Scripting

Help with Backup Shell Script for Network Device Configuration backup

HI all, im new to shell scripting. need your guidence for my script. i wrote one script and is attached here Im explaining the requirement of script. AIM: Shell script to run automatically as per scheduled and backup few network devices configurations. Script will contain a set of commands... (4 Replies)
Discussion started by: saichand1985
4 Replies

5. Shell Programming and Scripting

Script for Automatic Backup System

Hi Guys/ULF, Good day! Can anyone help me on how to create a program which will be used for our backup process and that will run automatically say every 30th day of the Month. Below is the given command to perform a backup process among all nodes/servers within the same cluster. ns cluster... (2 Replies)
Discussion started by: rymnd_12345
2 Replies

6. Solaris

Automatic backup through DD and crontab

Hi, I have not been working with Solaris for more than 10 years ago. Many things and details have ben forgotten. Hopes that some could help me with the problem. We used this scripts (below) for daily backup. The problems is following: I want to backup all partions/slice on a specific... (4 Replies)
Discussion started by: gjh
4 Replies

7. Shell Programming and Scripting

Automatic Email of Log Files in OSX

Hi, I am trying to write a shell script that will take the log files from a single folder (all ending with .log), put them into an archive, use something to encrypt the file, and then emailx to email the resulting encrypted archive to me. Of course, I am open to suggestions on how to improve... (1 Reply)
Discussion started by: DotNaBox
1 Replies

8. Shell Programming and Scripting

Shell script for sending automatic email to personal mail id

hi guys, I need a shell script to send mail automatically to my personal mail id like xxxx@hotmail.com but while experimenting with "mail" command I faced following problems. cat text1.txt | mail -s 'test mail' xxxx@hotmail.com command successfully executed but while checking for... (4 Replies)
Discussion started by: rrd1986
4 Replies

9. UNIX for Advanced & Expert Users

Automatic script

Hi, is it possible to automatically run a script (bash) when an event occurs? I mean, let's say that I (or one of my users) plug in a flash memory (USB) ... is it possible to run a script every time I do this action (let's say to log user, date and other infos on a file)? Thanks! Bye... (5 Replies)
Discussion started by: TShirt
5 Replies

Featured Tech Videos