1753963 Members
7330 Online
108811 Solutions
New Discussion юеВ

Bourne Shell script

 
TRUONG
Occasional Contributor

Bourne Shell script

Hello all,
Someone can give me a script in HP-UX 10.20 on Bourne Shell to verify the tape exists into drive before making a backup as well as:
if "tape is not into drive"
then
echo " Tape is not into drive. Do you want to continue ? Y/N"
if answer = "Y"
echo " Backup aborted"
exit
fi
else
fbackup -0vi/ -f /dev/rmt/0m -I /tmp/fbackup_index
fi

Thanks a lot



Sy-Hoang TRUONG
4 REPLIES 4
Andreas Voss
Honored Contributor

Re: Bourne Shell script

Hi,

try this:

dd if=/dev/rmt/0m of=/dev/null bs=5k count=1 >/dev/null 2>&1
if [ $? != 0 ]
then
echo "No Tape in Drive or Drive not ready"
else
fbackup ....
fi

Greetings

Andrew
John Palmer
Honored Contributor

Re: Bourne Shell script

You might also want to try the mt command with $TAPE set to the required tape device file e.g.

TAPE=/dev/rmt/1mn # bourne shell
export TAPE # bourne shell
or simply
export TAPE=/dev/rmt/1mn # ksh or posix

if mt rew 2>/dev/null # rewinds the tape
then fbackup ...
else echo "tape not loaded..."
fi

You could also extend this by using mt eof instead of mt rew (check the man pages for details). This will fail if the tape is actually loaded but is write protected.

Andrew Brain or Yong Ji
Occasional Advisor

Re: Bourne Shell script

try this script;

mt -t /dev/rmt/0m rew > /dev/null 2>&1
if [ $? != 0 ]
then
echo " There is no tape in the tape drive, you cannot continue"
echo " Backup aborted"
else
echo "Backup Starting"
fbackup -0vi/ -f /dev/rmt/0m -I /tmp/fbackup_index
fi

Regards..
Michelle
I'm spinning around
Tim Nelson
Honored Contributor

Re: Bourne Shell script

If you use cpio in the previous scenario it will even tell you if write protect is on.
ls /etc/copyright|cpio -omB > /dev/Tapedrive
(you will get any cpio messages here "
if [[ $? != 0 ]]
then
echo "Tape device not ready"
fi