[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

calling scp from ruby

Seid Rudy

9/7/2006 12:31:00 AM

I have a problem using "scp" from a ruby scrip. It copies my sql file to
the destination but it cuts the file the middle of line 290.
When i run scp manually i the copied file is normal.

I am using `` to call the unix command

Dir.chdir(sql_folder)
`scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`

Do you have any idea what i am doing wrong?

--
Posted via http://www.ruby-....

16 Answers

Jean Verger

9/7/2006 3:08:00 AM

0

What I'm using when scping is: scp -r dirToCopy destination ( -r for
recursive copy folder)

but, I believe that when dirToCopy or destination is remote, you should write:

USER@IP:/FOLDER/FILE

in your lines I can't see the @ sign

Could it be like:
`scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
`scp -r #{sql_folder} #{remoteUSER}@#{remotesIP}:/#{document_id}`

hope it helps,

Jean

On 9/7/06, Seid Rudy <seidom@hotmail.com> wrote:
> I have a problem using "scp" from a ruby scrip. It copies my sql file to
> the destination but it cuts the file the middle of line 290.
> When i run scp manually i the copied file is normal.
>
> I am using `` to call the unix command
>
> Dir.chdir(sql_folder)
> `scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
>
> Do you have any idea what i am doing wrong?
>
> --
> Posted via http://www.ruby-....
>
>

Jano Svitok

9/7/2006 6:50:00 AM

0

On 9/7/06, Jean Verger <jean.verger@gmail.com> wrote:
> What I'm using when scping is: scp -r dirToCopy destination ( -r for
> recursive copy folder)
>
> but, I believe that when dirToCopy or destination is remote, you should write:
>
> USER@IP:/FOLDER/FILE
>
> in your lines I can't see the @ sign
>
> Could it be like:
> `scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
> `scp -r #{sql_folder} #{remoteUSER}@#{remotesIP}:/#{document_id}`
>

(The OP seems to know the proper syntax, as he is able to do it by hand.)

(I have no clue what the cause is, these are just hint what to try)
- try another file (to see whether it is dependent on some pattern in
the file, or whether it transfers the same size all the time)
- try removing few line around that line
- try using system instead of ``
- look at the logs on the remote side

Michal Suchanek

9/7/2006 9:13:00 AM

0

On 9/7/06, Jan Svitok <jan.svitok@gmail.com> wrote:
> On 9/7/06, Jean Verger <jean.verger@gmail.com> wrote:
> > What I'm using when scping is: scp -r dirToCopy destination ( -r for
> > recursive copy folder)
> >
> > but, I believe that when dirToCopy or destination is remote, you should write:
> >
> > USER@IP:/FOLDER/FILE
> >
> > in your lines I can't see the @ sign
> >
> > Could it be like:
> > `scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
> > `scp -r #{sql_folder} #{remoteUSER}@#{remotesIP}:/#{document_id}`

scp file #{remotemachine}:

is fine, it copies file to remotemachine to the home of the user with
the same name (or as preconfigured in .ssh/config - you can create
shortcuts for remotemachine and configure what the remote username
should be). You can add /remotefolder/remotefile after the colon to
change the remote location.
> >
>
> (The OP seems to know the proper syntax, as he is able to do it by hand.)
>
> (I have no clue what the cause is, these are just hint what to try)
> - try another file (to see whether it is dependent on some pattern in
> the file, or whether it transfers the same size all the time)
> - try removing few line around that line
> - try using system instead of ``
> - look at the logs on the remote side

Try the -v switch to scp. Perhaps it will break even more but perhaps
it would do the same and show useful information.

Thanks

Michal

Paul Lutus

9/7/2006 7:00:00 PM

0

Seid Rudy wrote:

> I have a problem using "scp" from a ruby scrip. It copies my sql file to
> the destination but it cuts the file the middle of line 290.
> When i run scp manually i the copied file is normal.
>
> I am using `` to call the unix command
>
> Dir.chdir(sql_folder)
> `scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
>
> Do you have any idea what i am doing wrong?

I want to emphasize this is just an off-the-wall guess. The `backticked
code` is being forked, the parent process terminates prematurely, and the
forked process is killed, also prematurely.

Have you tried "system" instead of back-ticks? "system" returns a process
completion code, therefore it must wait until the process completes.

--
Paul Lutus
http://www.ara...

Pau Garcia i Quiles

9/7/2006 7:33:00 PM

0

Quoting Paul Lutus <nospam@nosite.zzz>:

Why won't you use Net::SFTP instead of calling the external scp?

> Seid Rudy wrote:
>
>> I have a problem using "scp" from a ruby scrip. It copies my sql file to
>> the destination but it cuts the file the middle of line 290.
>> When i run scp manually i the copied file is normal.
>>
>> I am using `` to call the unix command
>>
>> Dir.chdir(sql_folder)
>> `scp -r #{sql_folder} #{remotelogin}:#{remotesqlfolder}/#{document_id}`
>>
>> Do you have any idea what i am doing wrong?
>
> I want to emphasize this is just an off-the-wall guess. The `backticked
> code` is being forked, the parent process terminates prematurely, and the
> forked process is killed, also prematurely.
>
> Have you tried "system" instead of back-ticks? "system" returns a process
> completion code, therefore it must wait until the process completes.
>
> --
> Paul Lutus
> http://www.ara...
>
>



Joel VanderWerf

9/7/2006 8:30:00 PM

0

Pau Garcia i Quiles wrote:
> Why won't you use Net::SFTP instead of calling the external scp?

I can guess one reason. Net::SFTP doesn't work with key-based
authentication, only passwords, and there is no password given in OP's
code....

I hope that I am wrong and that this has changed recently.

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

Phlip

9/7/2006 9:02:00 PM

0

Pau Garcia i Quiles wrote:

> Why won't you use Net::SFTP instead of calling the external scp?

I have that question too. Do that do SSH format?

--
Phlip
http://www.greencheese.u... <-- NOT a blog!!!


Seid Rudy

9/8/2006 6:33:00 PM

0

Michal Suchanek wrote:

> Try the -v switch to scp. Perhaps it will break even more but perhaps
> it would do the same and show useful information.
>
> Thanks
>
> Michal


hi i tried -v option and found out that scp is getting chopped @ byte
40960. Any clue how i can change the byte limit?

debug1: Sending command: scp -v -r -t
/var/local/rudyserv/wilcox/hr/_sql/
Entering directory: D0755 0 069999
Sending file modes: C0644 40960 069999.sql
Sending file modes: C0644 0 069999.err
Sending file modes: C0644 0 069999.tst
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
debug1: fd 1 clearing O_NONBLOCK
debug1: Transferred: stdin 0, stdout 0, stderr 0 bytes in 0.1 seconds
debug1: Bytes per second: stdin 0.0, stdout 0.0, stderr 0.0
debug1: Exit status 0

rudy@localhost $ ls -al ../sql/069999/069999.sql
-rw-r--r-- 1 seid users 41455 Sep 9 03:18 ../sql/069999/069999.sql

--
Posted via http://www.ruby-....

Ara.T.Howard

9/8/2006 6:45:00 PM

0

Seid Rudy

9/8/2006 8:00:00 PM

0

unknown wrote:
> On Sat, 9 Sep 2006, Seid Rudy wrote:
>
> system "scp #{ src } #{ dst } >#{ log } 2>&1"
>
> are you on windows by any chance?
>
no, unix

I did that and i got an empty log.

I also rerun the script without deleting the sql file so it appended to
the file like it should. When i looked at the destination file i noticed
the file stopped at the same spot. But when i look up further to the top
of the destinatio file i noticed it had the a complete content of the
sql file followed by an incomplete content of the sql file. Ofcourse the
source has content of two complete sql files appended in one.




--
Posted via http://www.ruby-....