#!/bin/bash
a=`date +%Y%m%d`
IP1=10.0.0.14
IP2=10.0.0.69
PASSWORD=abc/123
PASSWORD2=123
expect << EOF
set timeout 1
spawn ssh root@$IP1 /bin/mkdir /home/mysqlbak_$a /usr/bin/mysqldump -u root -pabc/123 zabbix > /home/mysqlbak_$a/mysqlbak.sql
set timeout 1
expect "*: "
set timeout 1
send "$PASSWORD2\r"
expect eof
EOF
expect << EOF
set timeout 1
spawn ssh root@$IP2 /bin/mkdir /home/mysqlbak_$a /usr/bin/mysqldump -u root -pabc/123 zabbix > /home/mysqlbak_$a/mysqlbak.sq
l
set timeout 1
expect "*: "
set timeout 1
send "$PASSWORD1\r"
expect eof
EOF
expect << EOF
set timeout 1
spawn ssh root@$IP1 /usr/bin/rsync -avzP rsyncd@10.0.0.14::web /home/
set timeout 1
expect "*: "
set timeout 1
send "$PASSWORD2\r"
expect eof
EOF
转载于:https://blog.51cto.com/4249964/994675