简体   繁体   中英

How do I copy data from a remote system without using ssh or FTP Perl modules?

I have to write a Perl script to automatically copy data from remote server to my local system. The directory structure on remote systems is:

../log/D1/<date>.tar.gz
../log/D2/<date>.gz
../log/D3/<date>.tar.gz
../log/D4/<date>

and same on other server. I want to copy the data on local system in below format.

../log/S1/D1/<date>.tar.gz
../log/S1/D2/<date>.gz
../log/S1/D3/<date>.tar.gz
../log/S1/D4/<date>

and same for other servers ie S2, S3, etc

Also, no ssh supported Perl modules are available on remote server as well on local server and I dont have permission to install any Perl modules. The only good thing is that the connectivity is through password-less ssh keys.

Can anyone please suggest me any Perl code to get this done?

I believe you can access to shell command from perl.

So you can do this:

$cmd = "/usr/bin/scp remotefile localfile";
system $cmd; 

NOTE: scp is secure-copy -- a buddy of ssh.

This does not require ssh-perl module but it require ssh support on both (which I have).

Hope this helps.

I started to suggest the scp command line program, but it seems that there's a CPAN module for that (no surprise). Check out Net::SCP .

By using scp on your client (where you can install new Perl modules) you can copy files without having to install any new software on the remote system. It just needs to have the ssh server running - which you've said it does.

I'd say stop trying to make life difficult for yourself and get the system to support the features you require.

Trying to develop for such a limited/ locked down platform is not going to be cost-effective in the long run - you'll develop stuff more slowly and it will have more bugs.

A little developer time is way more expensive than a decent hosted VM / hardware box.

Get a proper host, it will definitely save money (talk to your manager about this).

From your query above I understand that you don't have much permissions to install perl modules or do any changes which require administrative privileges. I love perl but to automate things like this you should use bash instead of perl. Below is the sample code I am using with password less ssh keys.

#!/bin/bash

DATE=`date`
BASEDIR="/basedir"
cd $BASEDIR

for HOST in S1 S2 S3
do

        scp -q $HOST:$BASEDIR/D1/$DATE.tar.gz $HOST/D1/
        echo "Data copy from $HOST done"
done
exit 0

You can use different date formats like date +%Y%m%d for current date in format YYYYMMDD. Also you can use this link to learn different date formats.

Hope this helps.

You may not be able to install anything in system-wide lib directories, but there is nothing preventing you from installing modules in a location to which you have write-access. See How do I keep my own module/library directory?

This creates no more of a security issue than allowing you to write scripts on this system in the first place.

So, go forth and install Net::SCP .

It sounds like you want rsync. You shouldn't have to do any programming at all.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM