Problem with backup and copy a database

Hi,
I have many servers distributed on my customer locations all servers has MYSQL database.

I want to backup database for each server on server at my location using scheduler.

So I create Shell script file to backup and copy the database file from customer server to my server as following:

backup1.sh :

#!/bin/bash
mysqldump �uuser1 �puser1 mydata | bzip2 > /local/user1/DBBackupScheduler/db-`hostname`_`date +%Y-%m-%d`.sql.bz2

backup2.sh

#!/usr/bin/expect -f
spawn scp /local/user1/DBBackupScheduler/db-`hostname`_`date +%Y-%m-%d`.sql.bz2 10.10.10.10:/local/user1/DBBackupScheduler/
expect "Password:"
send "user1\n"
expect eof

I make in 2 files to avoid any problem, first file is working fine without any problem the second file make me lose my mind :confused: :

  • If I run the file like this:
User1@host:~> /local/user1/backup2.sh

Output:

/local/user1/backup2.sh: line 2: spawn: command not found
couldn't read file "Password:": no such file or directory
/local/user1/backup2.sh: line 4: send: command not found
couldn't read file "eof": no such file or directory
  • If I run the file like this:
User1@host:~> expect /local/user1/backup2.sh

Output:

spawn scp /local/user1/DBBackupScheduler/db-`hostname`_`date +%Y-%m-%d`.sql.bz2 10.10.10.10:/local/user1/DBBackupScheduler/
Password:
/local/user1/DBBackupScheduler/db-`hostname`_`date +%Y-%m-%d`.sql.bz2: No such file or directory
Killed by signal 1

But If I run scp command as it is it working fine without any problem

Please help

Google 'passwordless ssh' for information on getting scp to work without injecting insecurely-stored plaintext-passwords with the expect third-party brute-forcing tool.

Making keys:
ssh-keygen Tutorial � Generating RSA and DSA keys by Guy Rutenberg

Adding keys to a remote box:
How to Use RSA Key for SSH Authentication - Softpedia

I perefer to use expect, but this idea work great thank you all