Operating System - HP-UX
1833346 Members
2872 Online
110051 Solutions
New Discussion

Tarring all files in a directory

 
SOLVED
Go to solution
Jeff Picton
Regular Advisor

Tarring all files in a directory

Hi all

Can anyone provide a partial script which will tar all files in a directory then e-mail an account if the tar was successful or not ?

Thank you

Jeff
4 REPLIES 4
KapilRaj
Honored Contributor
Solution

Re: Tarring all files in a directory

cd $DIR;tar cvf /dev/rmt/0m .;if [ $? = "0" ]
then
echo "Tar succssful" |mail -s Results email_id@email.com
else
echo "Tar Unsuccssful" |mail -s Results email_id@email.com
fi

Regds,

Kaps
Nothing is impossible
Franky_1
Respected Contributor

Re: Tarring all files in a directory

Hi Jeff,

i can think of the following :

tar cfv /tmp/ /
if test $? = 0
then
sendmail < /tmp/
fi

Regards

Franky
Don't worry be happy
Muthukumar_5
Honored Contributor

Re: Tarring all files in a directory

We can know the successful of tar with it's return type as 0 or not,

testdir/file1 /testfile2

tar -cvf testdir.tar testdir 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
echo "$(date) Tar success" | mailx -s "Tar of testdir is successful" user@domain.com
else
echo "$(date) Tar failed" | mailx -s "Tar of testdir is failed" user@domain.com
fi
Easy to suggest when don't know about the problem!
Franky_1
Respected Contributor

Re: Tarring all files in a directory

Hi,

or maybe if you want to use "uuencode" :

tar cfv /tmp/ /
if test $? = 0
then
uuencode .rpt|sendmail
fi

Regards

Franky
Don't worry be happy