LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 04-30-2010, 02:59 AM   #1
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Rep: Reputation: 16
sudo but no sudo


hi guys

a customer asked me to create a menu for linux he also asked me to do this:

open like a command like where a user can execute commands...so for this the users have sudo enabled

the code below works OK.

But it has an issue when a command is executed but the command does not need sudo


like for instance

Code:
cd /
sudo: cd: command not found

how can I allow a user to execute all commands when a command does not need sudo

Code:
echo -e "Press Control+C to finish"
#echo -e " "
while true;
  do
  read whichcmd?"Insert Command: "
  sudo $whichcmd
done
thanks a lot
 
Old 04-30-2010, 04:31 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
In shells 'cd' may be a shell builtin. If a command requires sudo or not could be gathered from the list of commands for the user by comparing with output of 'sudo -l' (or use a static list of commands+args to compare against).
 
Old 04-30-2010, 09:30 AM   #3
kopper27
Member
 
Registered: Nov 2009
Posts: 147

Original Poster
Rep: Reputation: 16
Quote:
Originally Posted by unSpawn View Post
In shells 'cd' may be a shell builtin. If a command requires sudo or not could be gathered from the list of commands for the user by comparing with output of 'sudo -l' (or use a static list of commands+args to compare against).


how can i do that?

thanks a lot
 
Old 05-01-2010, 05:52 AM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,361
Blog Entries: 55

Rep: Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547Reputation: 3547
Code:
chkSudoCmd() { 
COMMAND="$@"; COMMAND=(${COMMAND}); 
sudo -l 2>/dev/null| while read LINE; do
 echo "${LINE}" 2>/dev/null|grep -q "${COMMAND[1]}"&& echo MATCH
done; }

~]$ chkSudoCmd sudo /usr/local/bin/javaMaker --type=sulawesi --ground=press --sugar=2
MATCH
 
  


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
LXer: The Ultimate Sudo FAQ To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 02:36 AM
Problem with SUDO : sudo: pam_authenticate: Module is unknown cristoph_ Linux - Software 2 03-02-2009 08:12 PM
sudo blkid vs. sudo fdisk -l problems alienexplorers Linux - Newbie 1 01-13-2009 01:35 AM
LXer: sudo, or not sudo: that is the question LXer Syndicated Linux News 0 02-07-2008 06:40 PM
Restricting Editing in Sudo (Advanced Sudo Question) LinuxGeek Linux - Software 4 11-04-2006 04:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:27 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration