Performing remote operations in a script

I have a scropt that looks something like this:

#!/bin/bash
ssh user@domain1.com
sleep 10
some_command
exit

ssh different_user@domain2.com
sleep 10
some_command
exit

However, the script is not logging into those accounts and doing the actions. The accounts are configured in my local known_hosts and I can copy / paste the lines one by one into the CLI to do what I need. How do I get a script to log into remote servers and perform actions there?

Thanks!

ssh user@domain1.com "some_command"

Thanks! That was almost too easy!

In the event that I need to do an if statement (check if file exists, if so then A if not the B), how can that be accomplished? Is my only option to write the script to the remote server, run it, then erase it?

You can do this:

$ ssh user@host "if [ ! -e example.file ]; then echo "no dice"; else echo "found it"; fi"