From the Fine Documetnation:
use Sudo;
my $su;
$su = Sudo->new(
{
sudo => '/usr/bin/sudo',
sudo_args => '...',
+
username => $name,
password => $pass,
program => '/path/to/binary',
program_args => '...',
# and for remote execution ...
[hostname => 'remote_hostname',]
[username => 'remote_username']
}
);
$result = $su->sudo_run();
And
sudo_run
The sudo_run function first checks the attributes to make sure the
+ minimum required set exists, and then attempts to execute sudo witho
+ut shell interpolation. You will need to take this into account in ca
+se you get confusing failure modes. You may set the debug attribute t
+o 1, 2, or 3 to get progressively more information.
The object will return a hash. The hash will have state informatio
+n within it. If the C'error' key exists, an error occured and you can
+ parse the value to see what the error was. If the run was successful
+, C'stdout' key exists, and its value corresponds to stdout output fr
+om the program run by sudo. Similarly the C'stderr' key will exist fo
+r a successful run, and the value corresponds to stderr output from t
+he program run by sudo. The C"rc" key will also be defined with the p
+rograms return code.
To summarize, the
new() method needs the path to the
sudo command rather than the
su, and
sudo_run() returns a hash that you will have to dig into.
I think what you want instead of your print "$result \n"; is
foreach my $key (sort keys %result) {
print("$key => $result{$key} \n");
}
(Note: Coded, not tested -- I have to run ....
----
I Go Back to Sleep, Now.
OGB