pseudo-solved: using sudo in a perl script
Madison Kelly
linux-5ZoueyuiTZhBDgjK7y7TUQ at public.gmane.org
Wed Dec 8 19:23:42 UTC 2004
Mike Waychison wrote:
> See perldoc -f open:
>
>
> "(You are not allowed to "open" to a command that pipes both in and out,
> but see IPC::Open2, IPC::Open3, and "Bidirectional Communication" in
> perlipc for alternatives.)"
Thanks for the reply!
Hmm, I was afraid of that. Well, what I decided to do, which seems to
work if not work most elequantly is have one open that calls:
open (SUDO, "|sudo -v\n");
print SUDO "$passwd\n";
close (SUDO)
Which sets the timestamp and then immediately call sudo again with
the actual command:
open (BLKID, 'sudo /sbin/blkid -c /dev/null 2>&1 |');
for (<BLKID>)
{
s/\n//;
$test=$_;
print "$test\n";
}
close (BLKID);
And then kill the timestamp as soon as I am done by calling:
system "sudo -K\n";
This saves me needing to define another 'use X', as well. Thanks
again for the help, hopefully at least this will help someone googling
for the same question in the future.
Madison
--
The Toronto Linux Users Group. Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml
More information about the Legacy
mailing list