The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Automatic FTP script texastig SCO 4 06-02-2009 07:08 PM
Automatic backup for sporadically connected clients with Box Backup iBot UNIX and Linux RSS News 0 08-29-2008 05:20 AM
Automatic script TShirt UNIX for Advanced & Expert Users 5 06-05-2008 05:34 AM
Script for automatic deletion of old files vivek_scv Shell Programming and Scripting 4 09-09-2007 02:57 AM
Automatic login script dayanand Shell Programming and Scripting 3 01-08-2006 07:46 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-02-2009
Wizard_1979 Wizard_1979 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
Email script when automatic backup is finsihed

Hello all,

i'm still new to this site and thought i might find some help here .
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 09:38 AM.. Reason: code tags, PLEASE!
  #2 (permalink)  
Old 10-02-2009
vgersh99's Avatar
vgersh99 vgersh99 is online now Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,122
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 (permalink)  
Old 10-02-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
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 (permalink)  
Old 10-02-2009
Wizard_1979 Wizard_1979 is offline
Registered User
  
 

Join Date: Oct 2009
Posts: 3
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.
  #5 (permalink)  
Old 10-02-2009
zaxxon's Avatar
zaxxon zaxxon is offline Forum Staff  
Moderator
  
 

Join Date: Sep 2007
Location: Germany
Posts: 2,285
Check for posts with "uuencode" using the search function of the forum. They will show you how to send mails with files as attachment.
  #6 (permalink)  
Old 10-02-2009
ggs ggs is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 12
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
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 12:14 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0