Operating System - HP-UX
1846914 Members
6144 Online
110256 Solutions
New Discussion

guru help needed for script

 
SOLVED
Go to solution
Anthony khan
Frequent Advisor

guru help needed for script

Hi All,

I wrote a script for backup, what the script is doing right now is if any arguments is missing It will exit, but since another program calling this script I don't want the to exit at any stage, rather i'll wait and the input. If the tape is not there it give a message and wait till the some put the tape in the drive and script is keep running in a loop. Can anyone put light here
3 REPLIES 3
harry d brown jr
Honored Contributor
Solution

Re: guru help needed for script

Anthony,

take this code:

# Checking if device is given

if [ -z "$DEVICE" ]
then
echo $MESSAGE1
echo $MESSAGE2
exit 1
else
mt -t "$DEVICE" rew
fi

if [ $? -ne 0 ]
then
echo "There is no tape"
else
echo " Tape is loaded."
fi



and replace it with this:
##############################
# Checking if device is given

if [ -z "$DEVICE" ]
then
echo $MESSAGE1
echo $MESSAGE2
exit 1
fi

mt -t "$DEVICE" rew
TAPEISLOADED=$?

while [ "$TAPEISLOADED" != "0" ]
do
echo "There is no tape"
# send an email here to notify someone
sleep 60
mt -t "$DEVICE" rew
TAPEISLOADED=$?
done

echo " Tape is loaded."

##############################
live free or die
harry
Live Free or Die
Jeffrey Davis_1
Frequent Advisor

Re: guru help needed for script

Hi Anthony. Maybe this will work. As you check to see wether or not each required element is present or not run each required element through a loop check. I will try to give an example:
# Checking to see if device is given
if [ -z "$DEVICE" ]
then
echo "Please enter valid device name."
echo "Press Enter when done."
read answer1
else
mt -t "$DEVICE" rew
fi

Something like this, if the parameter is not entered, prompt the user and the script will wait for their reply before continuing.
V. V. Ravi Kumar_1
Respected Contributor

Re: guru help needed for script

hi try this,

if [ -z "$DEVICE" ]
then
echo "Check Device name/insert the tape and press any key when ready"
read accept
else
mt -t "$DEVICE" rew
fi


regds
ravi
Never Say No