From: Rafał Długołęcki Date: Fri, 22 Mar 2013 17:21:15 +0000 (+0100) Subject: Added some validation and options to set ssh port. X-Git-Tag: 0.1~3 X-Git-Url: https://git.dlugolecki.net.pl/?a=commitdiff_plain;h=e0cd7b0eeb912f248da18b08515fd8690e252795;p=prj-utils.git Added some validation and options to set ssh port. --- 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");