Shirt Pocket Discussions

Shirt Pocket Discussions (https://www.shirt-pocket.com/forums/index.php)
-   General (https://www.shirt-pocket.com/forums/forumdisplay.php?f=6)
-   -   Run shellscript as root (https://www.shirt-pocket.com/forums/showthread.php?t=2517)

nicobos 06-20-2007 05:32 PM

Run shellscript as root
 
Hi all,

Before I start the copy I need to shut down groupware software and copy MySQL databases using a shell script.
After copy MySQL and groupware off course need to be started again.
These tasks need to be performed using shell scripts ran as root. How can I run a shellscript as root from SuperDuper!?

Nico

dnanian 06-20-2007 05:38 PM

Use the before/after shell script options in Advanced Options.

nicobos 06-20-2007 06:04 PM

Yeah, but how do I run a shell script as root instead of the user that launched SuperDuper?

Nico

dnanian 06-20-2007 06:23 PM

SD! runs that script authorized. Alternatively, you can suid the script...

nicobos 06-21-2007 03:14 AM

SD! may run authorized, but certainly not as root. I get authorization errors.
Maybe you can help me out how to suid the script.
Thanks in advance.

Nico

nicobos 06-21-2007 07:41 AM

I figured it out.
From Applescript you can run a shell command authenticated as a certain user.
From shell you can run Applescript commands.
This can combined in a shellscript like:

#!/bin/tcsh -f
osascript -e 'do shell script "echo " & "MySQL is being stopped"'
osascript -e 'do shell script "/Library/StartupItems/MySQLCOM/MySQLCOM stop" user name "root" password "my secret password" with administrator privileges'
osascript -e 'do shell script "echo "& "Wait 10 seconds"'
osascript -e 'delay 10'
osascript -e 'do shell script "echo "& "MySQL databases are being copied"'
osascript -e 'do shell script "cp -f -R /usr/local/mysql-max-5.0.27-osx10.4-i686/data /usr/local/mysql-max-5.0.27-osx10.4-i686/data_backup" user name "root" password "my secret password" with administrator privileges'
osascript -e 'do shell script "echo "& "Waits 10 seconds"'
osascript -e 'delay 10'
osascript -e 'do shell script "echo "& "MySQL is being started"'
osascript -e 'do shell script "/Library/StartupItems/MySQLCOM/MySQLCOM start" user name "root" password "my secret password" with administrator privileges'

Don't forget to chmod 755 the shell script file, otherwise you will get a permission error.

Nico

dnanian 06-21-2007 08:15 AM

There you go! :)


All times are GMT -4. The time now is 05:11 PM.

Powered by vBulletin® Version 3.8.9
Copyright ©2000 - 2022, vBulletin Solutions, Inc.