I am using the Net::Telnet module to log into a remote machine and run some commands. My problem is the commands need to be run as root. I am looking for a way to su to root after I telnet into the system as my user id, and then run the commands as root.
Here is my code so far:
#!/opt/perl/bin/perl
use Net::Telnet;
@arr = qw (mercury aurora apollo);
foreach (@arr) {
$host = $_;
$telnet = new Net::Telnet ( Timeout => 10,
Errmode => 'die',
Prompt => '/\$ $/i');
$telnet->open ("$host.hphc.org"
;
$telnet->login ('xxxxx', 'xxxxx');
@arr2=$telnet->cmd ('opcagt -status');
print "@arr2\n";
}
Here is my code so far:
#!/opt/perl/bin/perl
use Net::Telnet;
@arr = qw (mercury aurora apollo);
foreach (@arr) {
$host = $_;
$telnet = new Net::Telnet ( Timeout => 10,
Errmode => 'die',
Prompt => '/\$ $/i');
$telnet->open ("$host.hphc.org"
$telnet->login ('xxxxx', 'xxxxx');
@arr2=$telnet->cmd ('opcagt -status');
print "@arr2\n";
}