ssh to another server with different username
You want to use key-authentication http://ornellas.apanela.com/dokuwiki/pub:ssh_key_auth
- Generate your keys
ssh-keygen
- Copy the keys to your new box
ssh-copy-id -i ~/.ssh/id_rsa.pub me@otherhost.com
- ssh to other host without password
ssh me@otherhost.com
You can use expect to wrap ssh, but it's pretty hectic, and fails easily when there are network errors, so test it well or use a script specifically designed for wrapping ssh passwords. Key based authentication is better.
You can prevent interactive sessions by redirecting standard input from the null device, ie.
ssh me@destination destination-command < /dev/null
About placing the script in the source server, if the script you are running is local, rather than remote, then you can pass the script on standard input, rather than the command line:
cat bashscript.sh | ssh me@destination