-   Linux - Newbie (
-   -   Perl & Sudo Problem (

mclard 12-02-2004 07:17 AM

Perl & Sudo Problem
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.


Hangdog42 12-02-2004 08:59 AM

I think you would just use the system function.


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 01: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:

mclard 12-03-2004 05: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 12-03-2004 09: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 12:10 PM.