LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 05-27-2011, 09:16 AM   #1
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Rep: Reputation: 17
making a Multi tape backup wish to send email


Friends,

I have s script that standard users use to back up usb drives to lto4 tapes...

it asks for a JobNumber and sends an email upon success.
I recently expanded it to use Multiple tapes.

( the whole script is below - here is the meat )
sudo tar --totals -H pax -cMvf /dev/st0 *

my specific Q is ... if the system reaches the end of the tape it happily mentions in the terminal that one needs to put in a second tape...

what i would like to do is send an email that --It needs a second tape.
( it presently sends an email upon successful compleation - so you see the only way a person knows that they need a second tape is if they
1-- know that the drive they are backing up is < 800GB (lto4)
2-- they do not get a completion emails and the think to walk to the basement and see the request for a second tape.
---
I wish for an email that would tap them on the shoulder that : " you need to put in a second tape "

so -- if i know the exact syntax that shows in the terminal - which is:
Prepare volume #2 for `/dev/st0' and hit return:

then can i test for that somehow?

here is the script entire ---------------

#!/bin/sh
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~# vers 11 ; 2.25.2011 js
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~# pps production backUP
##-----------< assumes a chgrp users of /media
##-----------< assumes a 755 dir of /home/pps/pps_list
#######################################################

###----------------># start is there a tape test
sudo mt -f /dev/st0 status | grep error

if [[ $? -ne error ]]
then
echo "ALERT ========= you need a tape "
exit
else
echo " all is well-- you got a tape"
fi
###----------------># end is there a tape test
#
####----# get JobNum # enter w spaces
echo “Please provide the jobNum -----! 5 digits NO SPACES !”
read jobNum
echo “Thanks…Processing Your ${jobNum} Now”
###---i need a date
start=$(date)
Ntime=$(date)
CalcStart=$(date +%s)
echo $Ntime > /home/pps/pps_list/${jobNum}.txt

#---
#cd /media/*
cd /media/
#echo "dir is: `pwd`"

##-----how big is it # find in Num of bytes the size of dir
dirSize=$(du -bs /media/$jobNum* | awk '{print $1}')
echo $dirSize

##--end how big

####---# make a txt file - later it might get upld--dunno
####-for the tape the 00index.txt
echo $jobNum > /media/00index.txt
echo $Ntime >> /media/00index.txt
ls -Rlh >> /media/00index.txt

###-for big saver
ls -Rlh >> /home/pps/pps_list/${jobNum}.txt
echo $dirSize " bytes" >> /home/pps/pps_list/${jobNum}.txt

ls -R > /home/pps/pps_list/${jobNum}_short.txt
echo $dirSize " Bytes" >> /home/pps/pps_list/${jobNum}_short.txt
####----------------------------------------------------# the do ###-----------------------##
####----# make tape , assume 0
#
### ----------------vers1 just 1 tape assumed
#sudo tar --totals -H pax -cvf /dev/st0 *
#
### ----------------vers2 just multi tape allowed 4.23.2011 js ##-------##
sudo tar --totals -H pax -cMvf /dev/st0 *
#
###-----# start happytest
if [[ $? -ne 0 ]]
then
echo " backUP halt or error "
exit1
else

############
end=$(date)
CalcEnd=$(date +%s)
echo $end >> /home/pps/pps_list/${jobNum}.txt

diff=$(( $CalcEnd - $CalcStart ))
## my dif effort needs work - need to do min only
#echo "Task Duration "$diff >> /home/pps/pps_list/${jobNum}.txt

####-remove the 00index.txt
rm /media/00index.txt
####----------------------------------------------------# end do
####---------------------------------------------# Start mail
# email subject
SUBJECT="The Back Up Job Number: "$jobNum

# Email To ?
########### group
EMAIL="bu@tgroup.com"
########### devel
#EMAIL="jt@tgroup.com"

# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "saver drive backed up to tape"> $EMAILMESSAGE
echo ".................................................. " >>$EMAILMESSAGE
echo "the job: " $jobNum >>$EMAILMESSAGE
echo $dirSize " Bytes" >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo "Start Time: "$start >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo " End Time: "$(date) >>$EMAILMESSAGE
echo "-------------------------------------------------- " >>$EMAILMESSAGE
echo "machine = armstrong" >>$EMAILMESSAGE
echo ".................................................. " >>$EMAILMESSAGE
echo " " >>$EMAILMESSAGE
echo "total seconds "$diff >>$EMAILMESSAGE
####hour=`echo $diff/3600 | bc`
echo " " >>$EMAILMESSAGE
hour=$(echo $diff/3600 | bc -l)
echo "that is r N $hour hour" >> $EMAILMESSAGE

# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
#echo "subject is " $SUBJECT
#####----------------------------------------------# end mail

echo "*********************************************************"
echo " . "
echo "backup " ${jobNum} " DONE "
echo " . "
echo "It took "$diff

echo "--------------------------------------------------::good"
fi
###-----# end happytest
####- eject tape ** the whole eject merged w a tell maybe
#sudo mt -f /dev/st0 eject
#mt -f /dev/st0 eject
echo "eject with a 88888 then Label and be sure to Slide the RED for copy PROTECT NOW"

==================================================






thanks
 
Old 05-27-2011, 09:49 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Assuming that the tar process does not terminate when it reaches the end of a tape, but simply emits a request for a new tape, you are going to need to launch tar as a child process of something that is capable of reading tar's standard output and/or stderr stream. The parent process will have to monitor that stream, and test for the presence of the request for a new tape. That process will also have to be able to send the e-mail. For such a task, I would use Perl, but that is simply my weapon of choice; it is probably do-able in bash or any number of other scripting tools.

The meat of the solution would look something like this:
Code:
#! /usr/bin/perl -w
#
#	LQzimbot.pl  -- launches tar and watches for 'end-of-tape'
#

use strict;

    open( TAR, "sudo tar --totals -H pax -cMvf /dev/st0 *|" ) || die "Couldn't launch tar : $!\n";
    while( <TAR> ){
        if( $_ =~ m/end-of-tape-message/ ){
	    #
	    #  Your routine to send e-mails here
	    #
    	    print "Need new tape\n";
		
        }
        elsif( $_ =~ /some terminal error message/ ){
	    print "tar failed\n";
	    exit(1);
        }
    }
    close TAR;
    print "Done\n";
    exit(0);
You can fill in the tar messge strings as appropriate. I don't use tapes, so I'm not sure how tar knows if the tape is replaced. If it needs any user input to tell it to carry on, that would complicate matters.
Since all of the hard work is being done in Perl, I would probably write the entire thing in Perl, but you can pass exit status back to the bash script, and embed something like this sample into your shell script instead.

--- rod.

Last edited by theNbomr; 05-27-2011 at 09:50 AM.
 
Old 05-27-2011, 11:11 AM   #3
zimbot
Member
 
Registered: Nov 2005
Location: cincinnati , ohio . USA
Distribution: ubuntu , Opensuse , CentOS
Posts: 179

Original Poster
Rep: Reputation: 17
Thanks theNbomr

I know what you mean by "something that is capable of reading tar's standard output and/or stderr stream"
perl is not my strong suit

I will study on this and noodle with it.

thanks again ( makes me wish i had kept learning perl when i started learning perl --but sorta...........drifted )
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Multi-Volume Tape Backup Question Jerry_Christ Linux - Software 1 05-27-2011 09:27 AM
LXer: Script to backup MySQL tables and send them to your email LXer Syndicated Linux News 0 09-30-2010 05:00 AM
zfs send to tape backup custangro Solaris / OpenSolaris 2 03-17-2010 05:50 PM
How to backup more than one time on same tape using DLT tape? hocheetiong Linux - Newbie 3 01-30-2008 06:54 AM
Using a DDS5 tape drive to restore from a DDS3 backup tape. AndrewCAtWayofthebit Linux - Hardware 1 05-14-2006 09:15 AM

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

All times are GMT -5. The time now is 07:39 PM.

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