Transfert file with scp (ssh)

Hello everybody,

Every day, i need to transfert 1 file from one to another solaris server
by using scp (ssh).

i am looking a script or an exemple of the script to do it by first
checking the presence of the file, and then, transfert it and
re-transfert it if the transfert fails for some raison like a network
problem or remote host down.

Sorry, i am beginner, could you help me please.

Thanks a lot for your help

Best Regards
Rahan
Rahan [ Do, 08 November 2007 22:42 ] [ ID #1865332 ]

Re: Transfert file with scp (ssh)

On Thu, 08 Nov 2007 22:42:58 +0100, Rahan wrote:

> Hello everybody,
>
> Every day, i need to transfert 1 file from one to another solaris server
> by using scp (ssh).
>
> i am looking a script or an exemple of the script to do it by first
> checking the presence of the file, and then, transfert it and
> re-transfert it if the transfert fails for some raison like a network
> problem or remote host down.


while ! ssh otherhost test -f filename
do
scp filename otherhost:. || sleep 60
done
Icarus Sparry [ Do, 08 November 2007 23:11 ] [ ID #1865333 ]

Re: Transfert file with scp (ssh)

On 2007-11-08, Rahan <Rahan [at] rahan.net> wrote:
> Hello everybody,
>
> Every day, i need to transfert 1 file from one to another solaris server
> by using scp (ssh).
>
> i am looking a script or an exemple of the script to do it by first
> checking the presence of the file, and then, transfert it and
> re-transfert it if the transfert fails for some raison like a network
> problem or remote host down.


<untested>
scp file remote-machine:path/
while [ $0 -ne 0 ]; do
sleep 60
scp file remote-machine:path/
done
</untested>

I think it's understandable. $0 is the return value of the
last command. By convention, it equals 0 if everything was ok.

Best regards,
Claudio
Claudio [ Fr, 09 November 2007 19:40 ] [ ID #1866344 ]

Re: Transfert file with scp (ssh)

On 2007-11-09, Claudio wrote:
> On 2007-11-08, Rahan <Rahan [at] rahan.net> wrote:
>>
>> Every day, i need to transfert 1 file from one to another solaris server
>> by using scp (ssh).
>>
>> i am looking a script or an exemple of the script to do it by first
>> checking the presence of the file, and then, transfert it and
>> re-transfert it if the transfert fails for some raison like a network
>> problem or remote host down.
>
><untested>
> scp file remote-machine:path/
> while [ $0 -ne 0 ]; do
> sleep 60
> scp file remote-machine:path/
> done
></untested>
>
> I think it's understandable. $0 is the return value of the
> last command. By convention, it equals 0 if everything was ok.

I think you mean $? not $0.

--
Chris F.A. Johnson, author <http://cfaj.freeshell.org/shell/>
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
===== My code in this post, if any, assumes the POSIX locale
===== and is released under the GNU General Public Licence
cfajohnson [ Fr, 09 November 2007 20:00 ] [ ID #1866345 ]

Re: Transfert file with scp (ssh)

In article <slrnfj9acm.hp8.claudio [at] example.org>,
Claudio <claudio [at] example.org> wrote:
>On 2007-11-08, Rahan <Rahan [at] rahan.net> wrote:
>> Hello everybody,
>>
>> Every day, i need to transfert 1 file from one to another solaris server
>> by using scp (ssh).
>>
>> i am looking a script or an exemple of the script to do it by first
>> checking the presence of the file, and then, transfert it and
>> re-transfert it if the transfert fails for some raison like a network
>> problem or remote host down.
>
>
><untested>
>scp file remote-machine:path/
>while [ $0 -ne 0 ]; do
> sleep 60
> scp file remote-machine:path/
>done
></untested>
>
>I think it's understandable. $0 is the return value of the
>last command. By convention, it equals 0 if everything was ok.

Which shell are you using (where $0 is the return value) ?
gazelle [ Fr, 09 November 2007 20:13 ] [ ID #1866346 ]

Re: Transfert file with scp (ssh)

On 2007-11-09, Chris F.A. Johnson <cfajohnson [at] gmail.com> wrote:
> On 2007-11-09, Claudio wrote:
>> On 2007-11-08, Rahan <Rahan [at] rahan.net> wrote:
>>>
>>> Every day, i need to transfert 1 file from one to another solaris server
>>> by using scp (ssh).
>>>
>>> i am looking a script or an exemple of the script to do it by first
>>> checking the presence of the file, and then, transfert it and
>>> re-transfert it if the transfert fails for some raison like a network
>>> problem or remote host down.
>>
>><untested>
>> scp file remote-machine:path/
>> while [ $0 -ne 0 ]; do
>> sleep 60
>> scp file remote-machine:path/
>> done
>></untested>
>>
>> I think it's understandable. $0 is the return value of the
>> last command. By convention, it equals 0 if everything was ok.
>
> I think you mean $? not $0.
>

Ops!

sure. My mistake. I'm very sorry.

<tested>
scp name-of-file machine:path
while [ $? -ne 0 ]; do
echo cannot copy. Waiting...
sleep 300
scp name-of-file machine:path
done
</tested>

Best regards,
Claudio.
Claudio [ Fr, 09 November 2007 20:54 ] [ ID #1866347 ]

Re: Transfert file with scp (ssh)

Hello and thanks to all for your answers.

Cdlt
Rahan
Rahan [ So, 11 November 2007 20:44 ] [ ID #1867711 ]
Linux » comp.unix.shell » Transfert file with scp (ssh)

Vorheriges Thema: bash - test for no files matching *.foo
Nächstes Thema: different sed behaviour on mac os x and linux