Hoxt.com – Open Source Mirrors Apache, CPAN, PHP, MySQL, PuTTY, Linux Virtual Server, Linux Documentation Project, ProFTPD


su – Run a command after entering root password

For a better scripting automation and still retain the security of su/non-root login:

su -c "mysql -e 'SHOW STATUS;' "

This will return the status of mysql. Now you can run this via a regular user, then su, then mysql. You'll be asked for password twice, one for the regular user, one for root.

ssh nonroot@server "su -c \"mysql -e 'SHOW STATUS;' \""

You'll get "standard in must be a tty" error. Too bad! Nice concept but does not work like this. Now to solve this, I've seen some suggestion to use an expect script but not supplying the root password automatically. The expect script will ask for the password.

Update: no need for expect script, with just an ssh option "-t" to force it to ask for a tty (see man page for description). So the solution is this:

ssh -t nonroot@server "su -c \"mysql -e 'SHOW STATUS;' \""

Security is still there, you'll be asked for two different passwords, but you can now write a script to guide the process flow as you expected and not having to teach/say/request/instruct users to type in a certain command (eg: then type su, then type your xxx command). Love it eh!

Comments (0) Trackbacks (0)

No comments yet.

Leave a comment

No trackbacks yet.