Skip to main content
Question

Run script as sudo with graphical password entry


Forum|alt.badge.img+3

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?

8 replies

Forum|alt.badge.img+21
  • Contributor
  • 1028 replies
  • October 1, 2015

Questions:

1) What are you trying to accomplish?

2) Do you need this username and password to actually be authenticated/verified?


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 8 replies
  • October 1, 2015

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


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • October 1, 2015

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.


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 8 replies
  • October 1, 2015

We do not currently have casper in place fully yet. Once it is, then that would be the ideal way.


mm2270
Forum|alt.badge.img+16
  • Legendary Contributor
  • 7880 replies
  • October 1, 2015

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.


Forum|alt.badge.img+21
  • Contributor
  • 1028 replies
  • October 1, 2015

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.

my link text


Forum|alt.badge.img+3
  • Author
  • New Contributor
  • 8 replies
  • October 1, 2015

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.

!/bin/sh

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

Remove the Microsoft Office 2011 folder

rm -rfv /Applications/Microsoft Office 2011

Remove Office preferences

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

Remove the license file

rm -rfv /Library/Preferences/com.microsoft.office.licensing.plist
rm -rfv ~/Library/Preferences/ByHost/com.microsoft.*

Delete Application support

rm -rfv /Library/Application Support/Microsoft/

Remove receipts

rm -rfv /private/var/db/receipts/com.microsoft.*

Delete Application support in User Folder

rm -rfv ~/Library/Application Support/Microsoft/Office

Rename Microsoft User Data

cd ~/Documents
rm -mv Microsoft User Data ~Microsoft User Data osascript -e 'display alert "Complete" message "Microsoft Office is now uninstalled"'


Forum|alt.badge.img+10
  • New Contributor
  • 596 replies
  • October 2, 2015

make the script a postinstall and put it in a package
easy


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings