Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 12-02-2004, 07:17 AM   #1
LQ Newbie
Registered: Dec 2004
Posts: 10

Rep: Reputation: 0
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.

Old 12-02-2004, 08:59 AM   #2
LQ Veteran
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 418Reputation: 418Reputation: 418Reputation: 418Reputation: 418
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.
Old 12-02-2004, 01:55 PM   #3
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 66
Yes, just execute it from your system call as you would on the CLI, there is also a perl module if you prefer:
Old 12-03-2004, 05:57 AM   #4
LQ Newbie
Registered: Dec 2004
Posts: 10

Original Poster
Rep: Reputation: 0
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

Old 12-03-2004, 09:32 AM   #5
LQ Newbie
Registered: Dec 2004
Posts: 10

Original Poster
Rep: Reputation: 0
Got it working finally using the system('sudo') commands.
Thanks for all the help


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 04:20 PM
openbox & sudo hungrigerhaifisch Ubuntu 10 10-07-2005 06:22 AM
Apache & Perl problem ginda Linux - Software 8 02-18-2005 08:45 PM
SUDO & Perl mclard Programming 1 12-02-2004 01:56 PM
perl & apache problem tanmaya Linux - Software 0 04-07-2003 04:13 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:40 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration