Seq has asked for the wisdom of the Perl Monks concerning the following question:
xargs -a ~/servers -l1 -I'{}' ssh -t '{}' 'sudo aptitude full-upgrade'
Works, but it'll start to loose pty after one adds grep db ~servers|cut -d';' -f1 etc.
Anyway I wanted to use database, so I can make my life more difficult.
Everything else works, but that ssh is bit off. Script below works ok, no worries, but I need more.
I can execute commands OR run shell, but I need both in a same time.
I want to get interactive with commands. ;) Like sudo aptitude full-upgrade, which asks Yes or No.
Ofc I can add -y to that aptitude but there are more questions. Like, do you want to save your configurations or something.
And expect is not an answer.
Basically I want inject my commands to that shell and want it to stop after it's done, cause there will be more servers...
#!/usr/bin/perl use strict; use Net::SSH::Perl; my $host = '172.16.9.40'; my $username = 'power'; my $ssh = Net::SSH::Perl->new($host,$username,options =>["interactive +yes","identity_files $ENV{HOME}/.ssh/id_dsa"]); $ssh->login($username); my $cmd; #my $cmd="sudo aptitude update"; if ($cmd) { my($out, $err, $exit) = $ssh->cmd($cmd); print $out if $out; print $err if $err; } else { eval "use Term::ReadKey;"; ReadMode('raw'); eval "END { ReadMode('restore') };"; $ssh->shell; print "Connection to $host closed.\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Interactive commands via ssh
by haukex (Archbishop) on Feb 14, 2017 at 08:49 UTC | |
by Seq (Novice) on Feb 14, 2017 at 09:01 UTC | |
by Seq (Novice) on Feb 14, 2017 at 13:40 UTC | |
|
Re: Interactive commands via ssh
by haukex (Archbishop) on Feb 15, 2017 at 09:13 UTC | |
|
Re: Interactive commands via ssh
by Anonymous Monk on Feb 14, 2017 at 20:57 UTC |