I have wrote script to autologin scp and transfer specified file. I am using perl Net::SCP::Expect module for it.
Requirement: Net::SCP::Expect perl module is required for script.
Install required module:
Script name is autossh.pl
-----------------------START--------------------------
#!/usr/bin/perl -w
use strict;
use Net::SCP::Expect;
if ($#ARGV != 0 ) {
print "usage: autossh.pl\n";
exit;
}
my $server=$ARGV[0];
my $user = "orion";
my $password = 'mypassword';
my $remotedir = "/home/local/mydata/";
my $filelocation = "/home/remote/backup/";
print "Login...Starting scp...";
my $scpe = Net::SCP::Expect->new(host=>$server, user=>$user, password=>$password, recursive=>'1', auto_yes => '1', auto_quote => '0');
print "\nFILELOCATION:" . $filelocation . "*\n";
print "REMOTEDIR: " . $remotedir . "\n";
$scpe->scp($filelocation, $remotedir);
print "SCP complete\n";
-----------------------END--------------------------
To run script type.
#./autossh.pl servername.com
This script will copy /home/mydata local directory to remove server "remoteserver.com" at /home/remote/backup directory.
Requirement: Net::SCP::Expect perl module is required for script.
Install required module:
perl -MCPAN -e 'install
Net::SCP::Expect'
Script name is autossh.pl
-----------------------START--------------------------
#!/usr/bin/perl -w
use strict;
use Net::SCP::Expect;
if ($#ARGV != 0 ) {
print "usage: autossh.pl
exit;
}
my $server=$ARGV[0];
my $user = "orion";
my $password = 'mypassword';
my $remotedir = "/home/local/mydata/";
my $filelocation = "/home/remote/backup/";
print "Login...Starting scp...";
my $scpe = Net::SCP::Expect->new(host=>$server, user=>$user, password=>$password, recursive=>'1', auto_yes => '1', auto_quote => '0');
print "\nFILELOCATION:" . $filelocation . "*\n";
print "REMOTEDIR: " . $remotedir . "\n";
$scpe->scp($filelocation, $remotedir);
print "SCP complete\n";
-----------------------END--------------------------
To run script type.
#./autossh.pl servername.com
This script will copy /home/mydata local directory to remove server "remoteserver.com" at /home/remote/backup directory.