As for the ssh example, you can use RSA authentication so you don;t need to enter a password, and then start ssh (from a script) more or less like this:
ssh -l username 10.0.0.122 " script command #1
script command #2
script command #3
script command #4"
cat somescipt | ssh -l username 10.0.0.122 -
I didn't actually try this, but it should be possible, or at least quite similar.