You can use TCL/Expect to automate SSH logins to a remote server to execute a command on that server.
This automated login script can be modified to work with any command line program that prompts for passwords or user input. I have used similar scripts to automate CVS logins and updates, and I have automated many other tasks in linux. The following example will SSH into a server and restart apache.