[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Omaha.pm] Net::SSH::Perl and sudo or su



I'm a bit new to perl and am having a bit of trouble getting a sudo (or su for that matter) to work through Net::SSH::Perl.

Interactive with a shell doesn't seem to do anything for me.  And I'd like to not have to fuss with the sudoers to turn off the requiretty.


Snippets of my code utilizing it...

#!/usr/bin/perl -w
#---------------Includes------
----------
use strict;
use warnings;
#use Getopt::Std;
use Net::SSH::Perl;
use Term::ReadKey;
use Getopt::Long;

....

my $cmd = "sudo test";
my $ssh = Net::SSH::Perl->new($hos, interactive =>1, use_pty => 1, debug => 1, port => $port, protocol => '2,1', options => ["BatchMode yes"]) or die("Could not connect");

#$ssh->login($user, $pass);
$ssh->login($user);
#$ssh->shell;
my ($stdout, $stderr, $exit) = $ssh->cmd($cmd);
print "OUT:$stdout \nERR:$stderr \nEXIT:$exit \n";

....
Response from a sudo test

Use of uninitialized value in concatenation (.) or string at ./SerialPush.pl line 79.
OUT:
ERR:sudo: sorry, you must have a tty to run sudo
 
EXIT:1

...
Response from a su root test

Use of uninitialized value in concatenation (.) or string at ./SerialPush.pl line 79.
OUT:
ERR:standard in must be a tty
 
EXIT:1


Any ideas on how I can get this to work?
What I'm trying to do is get a perl script to move a file from tmp to etc, or just simply write a  config file to /etc on a ton of remote systems.