From e0cd7b0eeb912f248da18b08515fd8690e252795 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rafa=C5=82=20D=C5=82ugo=C5=82=C4=99cki?= Date: Fri, 22 Mar 2013 18:21:15 +0100 Subject: [PATCH] Added some validation and options to set ssh port. --- config | 1 + prj-upload-db.pl | 10 ++++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/config b/config index 185e382..7208176 100644 --- 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 diff --git a/prj-upload-db.pl b/prj-upload-db.pl index d670c15..695e36a 100755 --- a/prj-upload-db.pl +++ b/prj-upload-db.pl @@ -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"); -- 2.30.2