Backup shell scripting program

Good afternoon gentlemen...I'm writing a backup shell script on Fedora Linux server. The purpose of the script is back-up weekly files to an internal tape drive. I have everything execpt when the tape is finished at the recording, I need to develop an if statement so that when it reaches the end of the tape it will eject the tape and send a message to the administrator that the tape has been ejected. I have a sample script below, but the if statement is the one I need help with, what do I use to specify the tape is at the end, is it 0. Script below


!#/bin/sh

File_st="/var/log"
tape_drive="/dev/sto"
cd $File_st
find . print | cpio -ovH crc -O /dev/nst0

if ( $tape_drive = ????)
then

eject $tape_drive
mail "tape is finished" > admin@localhost

else

mail "date% this weeks backup is complete" > admin@localhost


any modifications will be welcomed.
ritruAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

wesly_chenCommented:
Hi ritru,

  The line should change to
find . print | cpio -ovH crc -O /dev/nst0
===>  find . -name <filename> -print -exec cpio -ovH crc -O {} /dev/st0 \;

   If you just copy whatever under /var/log, then just use "cpio". No need for find command.

   Besides, you can check the status of cpio, if it fail, then you need to check the tape or the backup log.
Not just check whether tape full (if tape were full, then the cpio would error out, and the status will be 1:fail).

Regards,

Wesly
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ritruAuthor Commented:
So what you saying is I can do an

if [$tape_drive == -1] then

eject $tape_drive
mail "tape has finished" > admin@localhost

else

cd $File_st
find . print | cpio -ovH crc -O /dev/nst0
mail "date% this weeks backup is complete" > admin@localhost

fi

This would resolve if the tape is full or not...One more question is that the correct command to prompt for the date or am I missing something.... My mail command is correct right?  Anyway thank you for time and patience.

0
wesly_chenCommented:
Well,
the return status code is stored in $status.

So if you do
cpio -ovH crc -O /var/log /dev/st0
and cpio fails for any reason including "tape full".
Then the $status is set to "1" automically.
So it should be:
--------------------------
cpio -ovH crc -O $File_st /dev/st0

if [ $status == 1 ] then
mail "backup failed" > admin@localhost
else
mail "date% this weeks backup is complete" > admin@localhost
fi
----------------------------

Regards,

Wesly
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux OS Dev

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.