The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Operating Systems > OS X (Apple)
.
google unix.com



OS X (Apple) OS X is a line of Unix-based graphical operating systems developed, marketed, and sold by Apple.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
sudo, use in script without prompt for password gauravgrover50 Shell Programming and Scripting 4 04-25-2009 08:26 AM
sudo command with password chebarbudo Shell Programming and Scripting 1 12-29-2008 08:13 AM
Works from bash prompt, but not from script! siegfried Shell Programming and Scripting 7 02-10-2008 02:56 PM
verify sudo password mdpalow Shell Programming and Scripting 0 12-20-2007 10:53 PM
sudo in OS X shell script without password prompt?? Brad_GNET UNIX for Dummies Questions & Answers 1 07-29-2005 06:36 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-27-2009
PatGmac PatGmac is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 1
Bash script prompt for sudo password?

I'm making a script that will be a double clickable .command file and I need it to prompt for the users admin password.

So far I have:

Code:
if [[ "$(/usr/bin/whoami)" != "root" ]]; then 
    sudo -p "Please enter your admin password: " date 2>/dev/null 1>&2
        if [ ! $? = 0 ]; then 
            echo "You entered an invalid password or you are not an admin/sudoer user. Script aborted."
            exit 1
        fi
fi
which does get the prompt, but the rest of the script does not run with sudo privileges as needed. What do I need to do for this to apply to the whole script?

Thanks.
  #2 (permalink)  
Old 04-30-2009
frank_rizzo frank_rizzo is offline Forum Advisor  
Resident BOFH
  
 

Join Date: Dec 2007
Posts: 423
the way your script is written is to only run the date comand with sudo. if you want to run other commands you should probably create a second script and call that instead of date.
  #3 (permalink)  
Old 05-01-2009
xbin xbin is offline
Registered User
  
 

Join Date: Feb 2007
Posts: 5
Try this code:

Code:
sudo -p "Please enter you admin password: " whoami 1>/dev/null && {sudo whoami;sudo whoami;whoami;sudo -k}
Let sudo do the work instead of doubling the effort. Note if the user fails to type their correct admin password or is not an admin user nothing else will run. Each command run as root must be preference with sudo. sudo -k will remove the timestamp so no other sudo commands will run without authentication.
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:55 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0