Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need to create a script to modify some data, which would require super user permission. Is there any way to automate this process via shell script on Mac 10?

Sample Script:

sed s/Hello/World/g /usr/local/opt/test.xml 

To run this script, the user needs super user permission, is there any way to provide root credentials in the script and execute?

share|improve this question

migrated from stackoverflow.com May 20 '11 at 23:30

This question came from our site for professional and enthusiast programmers.

does this need to be run on demand, or could it be run hourly say by cron? –  PurplePilot May 19 '11 at 19:37

1 Answer 1

You can change the permissions on the shell script file to automatically make it run as root.

From the chmod manpage:

4000    (the set-user-ID-on-execution bit) Executable files with
        this bit set will run with effective uid set to the uid of
        the file owner.  Directories with the set-user-id bit set
        will force all files and sub-directories created in them to
        be owned by the directory owner and not by the uid of the
        creating process, if the underlying file system supports
        this feature: see chmod(2) and the suiddir option to

A sample command might look like:

sudo chown root:root file.sh
sudo chmod 4755 file.sh
share|improve this answer
I am running this via shell script. I used expect to resolve this! thanks :) –  Santosh M Jul 1 '11 at 9:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.