LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-20-2006, 04:02 PM   #1
phatboyz
Member
 
Registered: Feb 2004
Location: Mooresville NC
Distribution: CentOS 4,Free BSD,
Posts: 358

Rep: Reputation: 30
Emailing after script run?


I have been using this backup script and I'd like for it to email me but the person who wrote it didn't include any logging. Can someone direct me the right way. What you see in red would be nice to get emailed. Thanks

#!/bin/sh
# full and incremental backup script
# created 07 February 2000
# Based on a script by Daniel O'Callaghan <danny@freebsd.org>
# and modified by Gerhard Mourani <gmourani@videotron.ca>
# modified for tape use by Chad Amberg <http://www.bluestream.org>

#Change the 3 variables below to fit your computer/backup

DIRECTORIES="/local/notesdata" # directories to backup
BACKUPTO=/dev/st0 # where to store the backups
TAR=/bin/tar # name and locaction of tar

#You should not have to change anything below here

PATH=/usr/local/bin:/usr/bin:/bin
START=`date +%s`

# Daily full backup
NEWER=""
echo "***** start time"
date
echo
if mt -f /$BACKUPTO status | grep "ONLINE"; then
echo "***** finding sockets"
find $DIRECTORIES -type s > sockets
echo
echo "***** setting compression on"
mt -f /$BACKUPTO compression 1
echo
# echo "***** setting type to DDS-3 Compressed"
# mt -f /$BACKUPTO setdensity 0x25
echo
echo "***** archiving"
$TAR $NEWER -cf $BACKUPTO $DIRECTORIES --exclude-from=sockets --absolute-names --totals # --exclude-from=tbackup.ignore
echo
echo "***** tape-drive status"
mt -f /$BACKUPTO status
echo
echo "***** ejecting tape"
mt -f /$BACKUPTO offline
echo
echo "***** end time"
date
else
echo "***** WARNING TAPE DRIVE IS OFFLINE, NO BACKUPS PERFORMED"
fi
FINISH=`date +%s`
diff=$((FINISH - START))
echo -n "***** Total Run Time: "
HRS=`expr $diff / 3600`
MIN=`expr $diff % 3600 / 60`
SEC=`expr $diff % 3600 % 60`
if [ $HRS -gt 0 ]
then
echo -n "$HRS hrs. "
fi
if [ $MIN -gt 0 ]
then
echo -n "$MIN mins. "
fi
if [ $SEC -gt 0 ]
then
if [ $MIN -gt 0 ]
then
echo "and $SEC secs."
elif [ $HRS -gt 0 ]
then
echo "and $SEC secs."
else
echo "$SEC secs."

fi
fi
 
Old 06-20-2006, 04:19 PM   #2
djwhitey
LQ Newbie
 
Registered: Mar 2006
Posts: 7

Rep: Reputation: 0
there is a way to do it w/ cron, b/c for a website i run i get a cron email every hour when the job completes... i set it up through cpanel though I'm not sure how you'd do it manually
 
Old 06-20-2006, 04:27 PM   #3
rh_bomani
Member
 
Registered: Apr 2006
Posts: 42

Rep: Reputation: 15
This is what I tried:

uname -a | mail -s "test". This put the 'uname -a' as the content of my message. So answere lies somewhere along there.
 
Old 06-20-2006, 04:44 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Here's the diff. OK, it's lame but should work:
Code:
--- scriptname     2006-06-20 00:00:00.000000000 -0800
+++ scriptname 2006-06-20 00:00:01.000000000 -0800
@@ -45,6 +45,7 @@
 else
 echo "***** WARNING TAPE DRIVE IS OFFLINE, NO BACKUPS PERFORMED"
 fi
+letsEmailThis() { 
 FINISH=`date +%s`
 diff=$((FINISH - START))
 echo -n "***** Total Run Time: "
@@ -70,4 +71,7 @@
 else
 echo "$SEC secs."
 fi
-fi
+fi; }
+letsEmailThis 2>&1 | mail -s "You want it, you got it, the biggest band in the land..." root
+
+exit 0
OK. So I'm lazy cuz basically you wrap in a function, call it and email the output.
Apply as "cat diff | patch --dry-run <insert scriptname here>". YMMV(VM).
 
Old 06-20-2006, 04:48 PM   #5
spirit receiver
Member
 
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
Code:
#! /bin/bash

exec 1> >(mail ada) 2>&1

echo "I want this to be emailed to ada."
echo "It even works with STDERR, you see?"
cat this-file-does-not-exist

Last edited by spirit receiver; 06-20-2006 at 05:04 PM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
'cannot stat' script in /etc/rc.d/, try to run script at startup quintan Linux - Software 1 11-21-2005 02:53 AM
Trigger script by SSHD failues and emailing commands... juanbobo Programming 1 08-18-2005 08:38 AM
script for emailing mysql data MrJoshua Programming 5 06-14-2005 01:32 PM
Script to run script in multiple directories... seabass55 Linux - General 5 07-06-2004 12:44 AM
on Network Up Script run? On Battery power run script? v2-ncl Linux - General 0 12-08-2003 09:34 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 03:00 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration