bash script for ssh login-

hi.
I need a bash script which can login to an other mashin via SSH and then run some commands and then return the result to my mashine.
I dont know where to begin, I think first I will need a ssh connection, dont know how to make it,
then , do I need a ftp connection between the 2 mashins to transfare data/files from mashine2 to mashine1 ?
is this things possible in bash ? it should be..
Please help.

Create public and private keys (with ssh-keygen -- read the man page) and install them.

Then you can use a command like:

remoteuser=myname
remotecomputer=example.com
ssh -l "$remoteuser" "$remotecomputer" "ls -l; date; "

To capture the result either redirect it to a file or store it in a variable with command substitution.

Hi.. I ran your script and it did work well, but I needed to type the password, how can I do it if I want the password inside the script ? so it runs automaticly without asking about password ?

I repeat:
Create public and private keys (with ssh-keygen -- read the man page)
and install them.

On the server, the public key should be appended to $HOME/.ssh/authorized_keys

on the client, the private key should go in '$HOME/.ssh', called id_XXX depending on the type of key.

The key pair should be made without password.

SSH User Identities

u can use ssh -l username IP "cmd"