I have few servers which needs updating and other kind of maintenance.

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"; }

In reply to Interactive commands via ssh by Seq

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.