Q:

ssh dynamically from script from any server

Ok, I have been searching for few hours and cannot seem to find the solution.
I have a file on a remote server to which one of the local users on that server has write access. I have the credentials. The requirement is:
The shell/perl script should automatically login to the server and write to that file.
The script should work from any server on the network without installing any extra packages as that will require me to sudo which will again ask for password and is therefore not possible from script.
I tried using expect but the server keeps saying spawn not found.
Please advise.

A:

#!/bin/bash
ssh -l username hostname "password; ~/updatefile.sh params"

Doesn't work.
To use the key method, try the following:
#!/usr/bin/env ssh-agent /usr/bin/env bash
KEYFILE=`mktemp`
cat << EOF > ${KEYFILE}
-----BEGIN RSA PRIVATE KEY-----
[.......]
EOF
ssh-add ${KEYFILE}

ssh user host command

# Remove the key file.
rm -f ${KEYFILE}

To generate a key for use, refer to the following: http://www.ece.uci.edu/~chou/ssh-key.html

