Hi wise ones,

I am trying to figure out how to use 'sudo su -' with a Net::OpenSSH. I've read the various documentation, but I am still stumped. What I want to do is log onto a box, sudo su - to a particular user, and then dump the crontab contents for that user.

Here is what I have so far -- basically, it sudos alright, but hangs before executing the crontab -l. I have to ctrl-c to get out of the script. When I ssh into the box, and sudo su - to the user manually, it works fine.

Any tips would be much appreciated. Thanks!

use strict; use warnings; use Data::Dumper; use Net::OpenSSH; my $user = 'user'; #this is just for testing -- final script will ask + for user's input. my $password = 'password'; #this is just for testing -- see above my $host = 'whater.host.to.check'; my $ssh = Net::OpenSSH->new($host, user => $user, password => $passwor +d, strict_mode => 0); my $test = $ssh->system('sudo su - user && crontab -l'); #once script + sudos, script hangs until I ctrl-c. print Dumper $test; print Dumper $ssh;

In reply to Net::OpenSSH with sudo su - by Anonymous Monk

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.