ssh commands in ksh question

Is there a way to shorten these commands? because this script asks for a password 3 times

scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/
ssh ${servernames[$iy]} /usr/local/bin/${script_name}
ssh ${servernames[$iy]} rm -f /usr/local/bin/${script_name}

Basically, I'm creating a script within a script, pushing it out to a server, execute it, and then removing it.

Thanks in advance.

You can get it down to two easily.

scp -p /usr/local/bin/${script_name} ${servername$iy]}://usr/local/bin/
ssh ${servernames[$iy]} /usr/local/bin/${script_name} && rm -f /usr/local/bin/${script_name}

You're obviously going into the remote node with privilege. Or /usr/local/bin is wide open which is a bad idea. I do not get the requirement for copying and deleting the script every time it is run. Is there no way to use protections to prevent it from being run? Or write it to someplace like /var/adm/.... where you can set restricted access?

To execute a simple script (that would execute ls -l / for example), my ideao would be to use the standard input :

echo "ls -l /" | ssh host "cat > /tmp/tmpscript && chmod +x /tmp/tmpscript && /tmp/tmpscript && rm /tmp/tmpscript"

Hope this can help...

X.

This is a good candidate for an expect script. You log in once, you run your commands, you log out.