Added some validation and options to set ssh port.
authorRafał Długołęcki <kontakt@dlugolecki.net.pl>
Fri, 22 Mar 2013 17:21:15 +0000 (18:21 +0100)
committerRafał Długołęcki <kontakt@dlugolecki.net.pl>
Fri, 22 Mar 2013 17:21:15 +0000 (18:21 +0100)
config
prj-upload-db.pl

diff --git a/config b/config
index 185e38296b3a58712e3cb646cb2b76267b596eeb..7208176b0ea4be190f8c76759274b6fa58a7fc8f 100644 (file)
--- a/config
+++ b/config
@@ -1,6 +1,7 @@
 remote_user    = USER
 remote_host    = some.host
 remote_dir     = 
+remote_port    = 22
 
 remote_db_name = DB_NAME
 remote_db_user = DB_USER
index d670c15c51c8b34bafa0424d1fe76f98ab4df81b..695e36a96d4938c17b06e6df0de672f8aafa9351 100755 (executable)
@@ -22,15 +22,21 @@ print "Compressing DB...\n";
 # upload db
 print "Uploading DB...\n";
 my $scp = Net::SCP->new($config{remote_host}, $config{remote_user});
-$scp->put("$config{remote_db_name}.tar.gz");
+$scp->put("$config{remote_db_name}.tar.gz") or die $scp->{errstr};
 
 print "Logging to $config{remote_host}...\n";
-my $ssh = Net::SSH::Perl->new($config{remote_host}, debug=>0);
+my %params;
+$params{port} = $config{remote_port};
+$params{debug} = 0;
+$params{use_pty} = 1;
+my $ssh = Net::SSH::Perl->new($config{remote_host}, %params);
 $ssh->login($config{remote_user}, $config{remote_pass});
 
 print "Unpacking DB...\n";
 my ($stdout, $stderr, $exit) = $ssh->cmd("tar -xzvf $config{remote_db_name}.tar.gz");
 print $stdout;
+print $stderr;
+
 
 print "Loading DB...\n";
 ($stdout, $stderr, $exit) = $ssh->cmd("mysql -u$config{remote_db_user} -p$config{remote_db_pass} $config{remote_db_name} < $config{remote_db_name}.sql");