Operating System - HP-UX
1751972 Members
4908 Online
108784 Solutions
New Discussion юеВ

Re: Can I set a timeout to cp?

 
SOLVED
Go to solution
Eric Antunes
Honored Contributor

Can I set a timeout to cp?

I cold backup everyday the database to a backup/test server via NFS but sometimes I shutdown that backup server and, since the backup script is sequential (shutdown db, cp and startup db), the database will not start if the backup server in not up or there is any kind of problem with NFS. I always can do this with 2 separate scripts but it is easier to cron just one.

So is it possible to set a 90 minutes timeout for cp for example?

Thanks,

Eric Antunes
Each and every day is a good day to learn.
49 REPLIES 49
Indira Aramandla
Honored Contributor

Re: Can I set a timeout to cp?

Hi Eric,

In you script after the database shutdown and when you issue the cp command you chekc for the retun code.

Whne the retun code is not zero it. not successfull then define the following and have the sleep wait_time in a loop.

Eg:-

WAIT_TIME=30
TIMEOUT=900
TIMER=0
Check with the return code of the cp command and then have the following in a loop.
while [ $retruncode -eq 1 ]
do
echo "Waiting for the database copy..."
sleep ${WAIT_TIME}
TIMER=`expr $TIMER + ${WAIT_TIME}`
if [ $TIMER -ge $TIMEOUT ] ; then
echo "\nWARNING: Timeout while waiting for copying to complete.\n"
RC=8
fi
done

IA
Never give up, Keep Trying
Muthukumar_5
Honored Contributor

Re: Can I set a timeout to cp?

I hope cp process will not make more time to process. You have to check the network connection with backup-server is up / not. If up then do copy then startup db again.

If you want to make timeout to cp process then,

execute cp operation in a process with background mode. Get the PID and sleep for 90 minutues and check PID is completed or not. If not kill that.

Example:

shutdown() {
..
}
copy() {

rcp backupserver:/tmp/test/*.db /database/

}
start(){
...
}


shutdown
copy &
PID=$!
start

hth.
Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Can I set a timeout to cp?

Sorry missed to say the check process and kill them as,

shutdown
copy &
PID=$!
sleep 90860
kill -9 $PID 2>/dev/null
start

hth.
Easy to suggest when don't know about the problem!
Stephen Keane
Honored Contributor

Re: Can I set a timeout to cp?

Muthukumar,

that means even if the cp is successful, you still have to wait 90 minutes!

You'd want to sleep for 1 minute and check the PID. Put the sleep/check in a loop that executes 90 times, unless the PID disappears in which case it would break/stop.

Muthukumar_5
Honored Contributor

Re: Can I set a timeout to cp?

I have outlined. That is all. :)

Basic concept is we have to make cp operation in background and control that with it's PID. We can add points like getting return code from cp and ps -ef | grep -v grep | grep -q $PID return code to make sleep 90 minutes operation.

hth.
Easy to suggest when don't know about the problem!
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Hi all,

I'm analysing the proposed solutions to assign points more correctly after.

Thanks,

Eric Antunes

Each and every day is a good day to learn.
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Ok, here's my test script:

WAIT_TIME=30
TIMEOUT=300
TIMER=0

SOURCE_DIR=/disc1/patches
DESTINATION_DIR=//patches

cp -R $SOURCE_DIR/* $DESTINATION_DIR

while [ $exit_code -eq 1]
do
sleep ${WAIT_TIME}
TIMER=`expr $TIMER + ${WAIT_TIME}`
if [$TIMER ge $TIMEOUT]; then
echo "\WARNING: ...!\n"
exit_code=8
fi

But I get:

"Syntax error at line 49 : `do' is not matched.". I'm missing something with the "while do" cicle...?
Each and every day is a good day to learn.
Stephen Keane
Honored Contributor

Re: Can I set a timeout to cp?

Yes

done

if .. fi

do .. done

Yogeeraj_1
Honored Contributor

Re: Can I set a timeout to cp?

hi eric,

you may also wish to add the "-p" switch when doing the cp -R...

-p will cause cp to preserve in the copy as many of the modification time, access time, file mode, user ID, and group ID as allowed by permissions.

hope this helps too!

regards
yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)