LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices

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

Rep: Reputation: 0
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
 
Old 12-02-2004, 08:59 AM   #2
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,791
Blog Entries: 1

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

Rep: Reputation: 65
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
 
Old 12-03-2004, 05:57 AM   #4
mclard
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

Mclard
 
Old 12-03-2004, 09:32 AM   #5
mclard
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
 
  


Reply


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


All times are GMT -5. The time now is 03:04 AM.

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