in reply to perl and sudo basic question
From the Fine Documetnation:
Anduse 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();
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.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.
I think what you want instead of your print "$result \n"; is
(Note: Coded, not tested -- I have to run ....foreach my $key (sort keys %result) { print("$key => $result{$key} \n"); }
----
I Go Back to Sleep, Now.
OGB
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: perl and sudo basic question
by yelekeri (Novice) on Jul 10, 2007 at 02:46 UTC | |
by yelekeri (Novice) on Jul 10, 2007 at 03:41 UTC | |
by Tomte (Priest) on Jul 10, 2007 at 06:20 UTC | |
by Argel (Prior) on Jul 10, 2007 at 06:36 UTC | |
by johngg (Canon) on Jul 10, 2007 at 09:21 UTC | |
by yelekeri (Novice) on Jul 10, 2007 at 14:54 UTC | |
by Tomte (Priest) on Jul 11, 2007 at 07:54 UTC |
In Section
Seekers of Perl Wisdom