Greetings wise ones. I have been trying to work with Net::SSH::Perl instead of Expect.pm and ssh, and up until now everything has seemed easy. I am trying to automate "apt-get installing" packages on multiple machines.
I thought:
($stdout,$stderr,$exit) = $ssh -> cmd ("apt-get install anjuta");
was pretty straightforward, but the ssh connection disconnects right before the package can be installed. I'm not sure what the workaround is. Can anyone offer suggestions? print "the output is: $stdout" looks like this:
the output is:Reading Package Lists... Building Dependency Tree... The following NEW packages will be installed: anjuta 0 packages upgraded, 1 newly installed, 0 to remove and 0 not upgrade +d. Need to get 0B/2633kB of archives. After unpacking 6955kB will be used +.
I think I am close but not quite there. For the curious, here is the whole script:
#!/usr/local/perl/bin/perl -w use Term::ReadKey; use Net::SSH::Perl; use Net::SFTP; my @machinelist = qw ( machine1.myip.com machine2.myip.com ); foreach my $machine (@machinelist) { print "We are going to clobber $machine\n"; } print "is this ok y/n? "; my $input = <stdin>; chomp $input; if (!($input eq "y")) { die; } print "what is your root password: "; ReadMode ('noecho'); my $rootpw=<stdin>; chomp $rootpw; ReadMode ('normal'); print "\n"; print "are you sure you want to continue y/n? "; $input = <stdin>; chomp $input; if (!($input eq "y")) { die; } foreach my $machine (@machinelist) { my $status=0; eval { my $ssh = Net::SSH::Perl->new($machine,protocol=>2); $ssh -> login ("root", $rootpw); my ($stdout,$stderr,$exit) = $ssh -> cmd ("apt-get install anjuta" +); #for debugging print "the output is:$stdout\n"; $status=1; }; if ($@) { $status=0; } if ($status) { print "$machine updated successfully.\n"; } else { print "there was a failure updating $machine\n"; } }
Thanks in advance for any guidance!
Rohit Mehta

UPDATE (for anyone interested). My problem was not a missing -y or anything, but a bad PATH. When I viewed the contents of $stderr, it became pretty apparent that my PATH was set incorrectly. So I changed my command to "export PATH=\"/sbin:/usr/sbin:/usr/bin:...\";apt-get ..." and voila! it works!
cheers!

In reply to Net::SSH::Perl with apt-get by Cmdr_Tofu

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.