How to pass password to scp command used in bash script? [duplicate]

Possible Duplicate:
Connect through SSH and type in password automatically, without using a public key

I have a bash script that makes dump of DB then copies file from one server to another but it always asks for password before connection.

scp file.tar.gz [email protected]:/backup

Is there a way to pass password directly into script ?


Use the tool sshpass

sshpass -p 'password' scp file.tar.gz [email protected]:/backup 

Rather than using root create an account just for this job. Use public keys without a passphrase instead of passwords.

scp -i /home/backupuser/.ssh/id_rsa [email protected]:/backup

By using a special account for the backup on the destination system you are not exposing your root password.