I am able to log in to the remote host via putty and using my account I am able to 'sudo su' without a problem. However when I try to do it using my code it errors out with "PROCESS_MUX_NEW_SESSION: tcgetattr: Inappropriate ioctl for device" message. I have been able to get the code to work with Net::Expect but I would like to avoid using expect in this context. The ssh connection establishes without a problem, and the scp works well.

The code works through a series of hosts listed in a file, and for each host available it SCPs a file to that host, and then runs a script that requires elevated privileges and uses the information in the file that was SCPed.

So two things to look at here:

1. Is my code for executing the sudo command correct? Am I missing something specific to OpenSSH?

2. I have seen it suggested in many places that "ssh -t" be used. However I have not found how to designate the -t in the Net::OpenSSH->new operators. How would one do this?

The "sudo" block is pretty much a cut and paste from the CPAN OpenSSH documentation. Things I have tried in the "sudo" block:

Removed the STDIN entry, removed the prompt modificaitons, with and without the STDIN, tried it as a straight "sudo su" command. Suggestions appreciated...

Here is my code. There may be some typos, and if it looks like a variable is missing, it will be because I tried to take out all the "trash" variables that no longer have any meaning and various print statements that help follow the flow when running. The names are changed to protect the guilty:

#!/usr/bin/perl use strict; use warnings; use DateTime; #for some functionality that will come later. use Net::OpenSSH; my $cur_ip; my $cur_name; my $user = "deryoosername"; my $pass = "derpassverden"; my $sudo_pass = "dersoodoopass"; my $target_file = "target-ip-name.txt"; open (TARLIST, $target_file) or die "Can't open file: $!"; while (<TARLIST>) { chomp; ($cur_ip, $cur_name) = split /\t/; $cur_name =~ s/[\s]+//g; print "$cur_ip\t"; print "$cur_name\n"; my $ssh = Net::OpenSSH->new($cur_ip, user=>$user, password=> +$pass, timeout=>2); next if $ssh_error and print "Can't SSH to host $cur_name\n" + . $ssh->error . "\n"; my $remotepath = "/Pathto/remote/new.filename"; my $localpath = "/localdir/fileto.move $ssh->scp_put($localpath, $remotepath); my $file_list = $ssh->capture("ls -l"); print "$file_list\n"; my @sudo_out = $ssh->capture({stdin_data => "$sudo_pass\n"}, 'sudo', '-Sk', '-p', '', '--', 'su'); } close TARLIST;

In reply to Sudo with Net::OpenSSH fails with PROCESS_MUX_NEW_SESSION: tcgetattr: Inappropriate ioctl for device by jester47

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.