Saturday, November 04, 2006

Some tips for executing remote scripts

It is sometimes useful to execute scripts remotely via ssh, and have those scripts execute other scripts or even other remote scripts via ssh. The following tips might come in handy...

If your script requires any type of terminal interaction, you might need to specify the -t command line option to ssh in order for a pseudo-terminal to be allocated to your session. This way you will be able to enter passwords, etc.

If your script requires access to shell environment variables, add -l to the 'slash bang' (I keep on forgetting the proper name for this) line, e.g. #!/bin/bash -l

If you need to execute certain commands as another user, e.g. root, and you don't want to make the script setuid, then rather create a separate script and execute it with su -c from the first script. Simply using su in the first script will not work.

0 comments: