Posted on 10-01-2015 10:31 AM
Is there a way to run the sudo command in a Shell script but have it ask for the password in a GUI window similar to the one attached?
Posted on 10-01-2015 10:45 AM
Questions:
1) What are you trying to accomplish?
2) Do you need this username and password to actually be authenticated/verified?
Posted on 10-01-2015 10:49 AM
Created a script that deletes all of the files for office 2011. see here Some of the files require the command to be run with the sudo command. To make it more user friendly, I would like for it to prompt for the password vs being typed in the command prompt
Posted on 10-01-2015 10:54 AM
Why not run this through a Self Service policy or some other way via Casper? It would run it as root to start with, so no user level authentication required.
Posted on 10-01-2015 10:56 AM
We do not currently have casper in place fully yet. Once it is, then that would be the ideal way.
Posted on 10-01-2015 11:03 AM
Oh, well, that's a whole different ballgame then.
You may have luck using an Applescript call to get the dialog to come up.
/usr/bin/osascript << EOF
set fullPath to do shell script "echo "scripts full path goes here"
do shell script "sudo " & fullPath with administrator privileges
EOF
I believe that will send up the authentication dialog. Only issue is that it says AppleScript Editor wants to make changes, or something like that.
Posted on 10-01-2015 11:05 AM
Well, one of the methods we've used this for was they keychain first aid self service that used CocoaDialog to pop up this very window so they could enter their current username and password to then have the script in the background generate a new keychain.
Run through this thread for some ideas. I specifically used Andrina's stuff that's referenced. I'm trying to find the original post of that. She was at the JNUC one year and presented all sorts of helpful items...especially once you have Self Service available to users. Her script is linked in that thread though.
Posted on 10-01-2015 11:33 AM
Here is the script I have so far. currently to run it I do "sudo sh screptname.sh" I would like for the sudo command to be included in the script and have it prom for a password in a guy window. I tried the applescript way but because the script has so many lines and paths I was having issues with syntax.
osascript -e 'tell app "System Events" to display dialog "This will remove Microsoft Office 2011 and all of its components. Any files or documents created by these apps will not be touched. Click Ok to continue."'
echo After uninstall you will need to reinstall Silverlight if it was previously installed
rm -rfv /Applications/Microsoft Office 2011
rm -rfv ~/Library/Preferences/com.microsoft.*
rm -rfv /Library/PrivilegedHelperTools/com.microsoft.office.licensing.helper
rm -rfv /Library/LaunchDaemons/com.microsoft.office.licensing.helper.plist
rm -rfv /Library/Preferences/com.microsoft.office.licensing.plist
rm -rfv ~/Library/Preferences/ByHost/com.microsoft.*
rm -rfv /Library/Application Support/Microsoft/
rm -rfv /private/var/db/receipts/com.microsoft.*
rm -rfv ~/Library/Application Support/Microsoft/Office
cd ~/Documents
rm -mv Microsoft User Data ~Microsoft User Data
osascript -e 'display alert "Complete" message "Microsoft Office is now uninstalled"'
Posted on 10-01-2015 09:39 PM
make the script a postinstall and put it in a package
easy