Operating System - HP-UX
1755144 Members
4420 Online
108830 Solutions
New Discussion юеВ

Can I set a timeout to cp?

 
SOLVED
Go to solution
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Will this work, anylysing the cp.log and, simultaneously, counting?

cp -R $SOURCE_DIR/* $DESTINATION_DIR > /disc2/.../cp.log
2>&1

Each and every day is a good day to learn.
Sandman!
Honored Contributor

Re: Can I set a timeout to cp?

> The problem is: when the NFS server is up everything runs ok but, when it is
> down(actual situation), it stops at the cp instruction.

that's exactly why you need to first ping the nfs server && then kick-off the copy.

ping && cp -R

The purpose here is that the entire command line works or fails as a unit. Only iff the ping succeeds does the copy kickoff and if the ping fails the copy never gets executed.

see script attached...

enjoy!!!
A. Clay Stephenson
Acclaimed Contributor

Re: Can I set a timeout to cp?

Just because ping works (or for that matter doesn't work) is really no indication of the status of NFS. Moreover, the return status of ping is far from reliable. It will reurn non-zero for host not found but 0 if it can ing but with errors.

If this were me I would do something like this:

df -F nfs /desiredmountpoint

If that returns a zero status then you can assume that NFS is available. Of course, you need a timeout mechanism for this as well.

This would be my approach:

TDIR=${TMPDIR:-/var/tmp}

timeoutcmd.pl -t 20 "df -F nfs /desiredmountpoint" > /dev/null 2>/dev/null
STAT=${?}
if [[ ${STAT} -eq 0 ]] # df ok
then
timeoutcmd.pl -t 5400 "cp -p file1 file2 /desiredmountpoint" > /dev/null 2>/dev/null
STAT=${?}
if [[ ${STAT} -ne 0 ]]
then
echo "Cp failed; status ${STAT}" >&2
fi
else
echo "NFS unavailable; status ${STAT}" >&2
fi
exit ${STAT}


Note: This is not the same Perl script posted earlier:

If it ain't broke, I can fix that.
Eric Antunes
Honored Contributor

Re: Can I set a timeout to cp?

Hi Clay,

I'm testing your perl script now. Is there any good manual about perl?

Hi Sandman,

The problem is that the command "ping && cp -R " never ends when the server is down (actual situation to test the script): I have to kill the ping processes...

Best Regards,

Eric Antunes

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

Re: Can I set a timeout to cp?

Clay,

With the NFS server down I get "NFS unavailable; status 127".


With the NFS server up, I still get "NFS unavailable; status 127"...

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,

From the command line, I get:

interpreter "/usr/bin/perl" not found
Each and every day is a good day to learn.
Muthukumar_5
Honored Contributor

Re: Can I set a timeout to cp?

can you find perl utility as,

find / -name "perl"

which perl

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

Re: Can I set a timeout to cp?

I found one perl interpreter in /usr/contrib/bin/perl...
Each and every day is a good day to learn.
Muthukumar_5
Honored Contributor

Re: Can I set a timeout to cp?

When you are going to ping then use finite count as,

ping -n 1

ping -n 1 1>/dev/null 2>&1
if [[ $? -eq 0 ]]
then
action;
else
echo 'server failed'
fi

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

Re: Can I set a timeout to cp?

Now (with /usr/contrib/bin/perl), I get:

"NFS unavailable; status 255"
Each and every day is a good day to learn.