Help with Script to Access Remote Files

I need to access files on remote servers and need to do this in a script because there are 100's of servers and 1000's of files.

I've tried

ssh user@host 'ls -l /dir path/fileName'

but cannot figure out how to deal with the prompt for password (here document is of no help). I've read of a way to setup the local and remote hosts to permit ssh command to execute with out password but that is not a viable option in this case.

Any suggestion on how to get a password into ssh or perhaps another method of accessing the file information appreciated.

Thanks for your consideration... tw

On the local machine:

ssh-keygen rsa

Then copy the contents of $HOME/.ssh/id_rsa.pub to $HOME/.ssh/authorized_keys on the remote machine.

Make sure that only you can read the directory .ssh and the files it contains on both local and remote machines.

You should now be able to ssh to the remote machine without needing a password.

Thanks but that is not a practical solution since there are somewhere around 600 servers and the list of servers changes frequently. I'm thinking the way to go is with an expect script and am trying to see if I can get that to work for me.

I will likely use your suggestion in other applications and do appreciate it. Thanks.