1、安装expect
2、expect.sh
#!/usr/bin/expect
set timeout 3600
set host [lindex $argv 0]
set passwd [lindex $argv 1]
set filepath [lindex $argv 2]
set dirpath [lindex $argv 3]
set user [lindex $argv 4]
spawn scp -r $filepath $user@$host:$dirpath
expect "*password:" { send "$passwd\n" }
expect eof
3、file_syn.sh
#!/bin/bash
host=***
passwd=***
filepath=/home/log.txt
dirpath="/home/"
user=root
./expect.sh $host $passwd $filepath $dirpath $user
echo "end"
4、使用crontab执行脚本
10 1 * * * /file_syn.sh