Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > macOS > Sudo with a shell script?

Sudo with a shell script?
Thread Tools
Jaey
Mac Elite
Join Date: Dec 2003
Status: Offline
Reply With Quote
Jan 2, 2007, 04:53 AM
 
I know that if I open up the Terminal and do
$ sudo blahblahblah
I get a prompt for my password. Is there anyway, though, to run sudo from within a shell script and somehow enter my password in the same line?
I mean something along the lines of
sudo whatever -p mypassword
(Yes, I know -p is not for entering my password)
     
Mithras
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Jan 3, 2007, 12:21 PM
 
No, because it's a bad idea.
Either use 'sudo' in the script and supply your password when requested, or write a two-line C program that calls your script, compile it, and then make it owned by root and turn on the setuid bit.
     
WJMoore
Grizzled Veteran
Join Date: Jan 2002
Location: Melbourne, Australia
Status: Offline
Reply With Quote
Jan 3, 2007, 04:58 PM
 
Better yet edit the /etc/sudoers file (using: sudo visudo) to permit the action you are trying to perform without a password. sudo is designed to give selective access to things with and without a password as desired. man sudoers and man sudo might be useful in working out what exactly to put in the file.
     
   
Thread Tools
 
Forum Links
Forum 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 On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 12:36 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,