LinuxQuestions.org
Review your favorite Linux distribution.
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 10-29-2008, 07:07 AM   #1
etomato
LQ Newbie
 
Registered: Oct 2008
Posts: 3

Rep: Reputation: 0
In a perl script, how to test if user has sudo execute w/o password ?


In a Perl script I execute an command with sudo.

I need to capture the command's output to an array and must execute the command with sudo without entering a password.

How to test if sudo is setup correctly before executing the command?
Or how to redirect if prompted for a password so I can parse the output?

my $cmd = 'sudo /usr/sbin/sanpath-command -l';
@cmdStdout = `$cmd`;

Is there something I can do via the shell within my Perl script?

Thanks.
 
Old 10-29-2008, 08:45 PM   #2
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
If you don't know in advance if you need a passwd, all you can do is run it and see.
You can capture the output into a scalar (not array) and parse that.
You can also look at these 2 modules that enable fine-grained control:

http://perldoc.perl.org/IPC/Open2.html
http://perldoc.perl.org/IPC/Open3.html
 
Old 11-02-2008, 03:16 PM   #3
etomato
LQ Newbie
 
Registered: Oct 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Question

Quote:
Originally Posted by chrism01 View Post
If you don't know in advance if you need a passwd, all you can do is run it and see.
You can capture the output into a scalar (not array) and parse that.
You can also look at these 2 modules that enable fine-grained control:
Not what I am looking for.

WITH A SCRIPT I need to initially and continuously test that my script can execute a command with sudo and without having to enter a password.

And without having to install yet another Perl module.

The script will run on AIX, Solaris and Vmware ESX Linux.
 
Old 11-02-2008, 03:55 PM   #4
Quakeboy02
Senior Member
 
Registered: Nov 2006
Distribution: Debian Squeeze 2.6.32.9 SMP AMD64
Posts: 3,245

Rep: Reputation: 121Reputation: 121
What is it that you're trying to do that you can't know up front that you have permission to do it?
 
Old 11-02-2008, 09:05 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Those are Core modules (ie part of the std install): http://perldoc.perl.org/5.8.8/index-modules-I.html
 
Old 11-03-2008, 06:35 AM   #6
etomato
LQ Newbie
 
Registered: Oct 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by Quakeboy02 View Post
What is it that you're trying to do that you can't know up front that you have permission to do it?
The commands are to query SAN path and the output will be parsed.

Sudo to permit execution might have been granted.
Sudo to permit execution might have been granted but erroneously removed.

The Perl version varies and definitely not 5.8.

And I have over 700 servers to deploy this on. (aix, linux, solaris)

Again, I need an automated method to test that sudo without password is working.

Any ideas?

Last edited by etomato; 11-03-2008 at 06:36 AM.
 
Old 11-19-2008, 11:18 PM   #7
Stone53
LQ Newbie
 
Registered: Nov 2008
Posts: 1

Rep: Reputation: 0
why not this? havent tried it but this would be my first shot.

my $cmd = 'sudo /usr/sbin/sanpath-command -l';
$cmdStdout = `$cmd`;
#check the output if its asking for the password
if ($cmdStdout !~m/passw/i)
{
print "no password required\n";
}
else
{
print "password required\n"
}
 
  


Reply

Tags
aix, esx, perl, solaris, sudo, vmware


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
bash - how to test, if a script is exececuted with sudo ? almatic Programming 6 10-19-2008 04:36 PM
How do I use sudo in a script without asking for password? Usalabs Linux - General 1 08-28-2008 02:59 PM
Shell script sudo without password prompt under Darwin? lhouk Other *NIX 3 02-08-2008 12:16 PM
Running a script as root with sudo without entering the user password kloss Linux - General 8 10-10-2005 12:39 PM
Why cant i execute a perl script dude4you Linux - Newbie 2 03-02-2004 06:50 PM


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

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