toxicsoftware.com

RANDOMIZE USR 0

toxicsoftware.com header image 2

Using a password to run shell scripts as root

September 29th, 2004 · Comments · Default

Here’s a little shell script to allow you to run the script as root without having to manually sudo it or set the setuid flag on the file. The script will prompt for your password and the running will user will need to be in the sudoers list (basically any Mac OS X admin user). Make sure the file is executable too.

#!/bin/sh
if [ $USER = 'root' ]; then
    echo 'I am root! Put your root script here!'
else
    osascript -e "do shell script \"$0\" administrator privileges true altering line endings false"
fi

Tags:

 
close Reblog this comment
blog comments powered by Disqus