LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Perl & Sudo Problem (http://www.linuxquestions.org/questions/linux-newbie-8/perl-and-sudo-problem-261682/)

mclard 12-02-2004 06:17 AM

Perl & Sudo Problem
 
Hi
Im trying to run a perl script that runs the sudo command. Can anyone help me and show me the correct way to run the sudo command from within the perl script.
Hope someone can help.
Thanks

Mclard

Hangdog42 12-02-2004 07:59 AM

I think you would just use the system function.

Code:

system ('sudo command');
Of course you'll have to set up your commands in sudo to not require a password or you'll have to write code that can handle sending a password when sudo requests it.

david_ross 12-02-2004 12:55 PM

Yes, just execute it from your system call as you would on the CLI, there is also a perl module if you prefer:
http://search.cpan.org/~landman/Sudo-0.10/lib/Sudo.pm

mclard 12-03-2004 04:57 AM

Could anyone tell me what the correct syntax for the sudo command then.
Im using


system ('sudo -u ****** /usr/sbin/useradd $newuser');

with no success

I know its an unsecure way of doing things but its on a small private network so im not too worried.

Many Thanks for the help so far

Mclard

mclard 12-03-2004 08:32 AM

Got it working finally using the system('sudo') commands.
Thanks for all the help


All times are GMT -5. The time now is 03:26 PM.