Linux自动上传更新文件

cat sh-push-serv.sh

#!/bin/sh
src_dir=./boxkeeper
dest_dir=/opt/boxkeeper
host=192.168.22.11
port=60139
username=root
password='1234'
 

# 将远程服务器上的文件拷贝到本机
./sh-expect-scp.expect $host $port $username $password $src_dir $dest_dir
 
echo "end

cat sh-expect-scp.expec

#!/usr/bin/expect

set timeout 3600
set host [lindex $argv 0]
set port [lindex $argv 1]
set username [lindex $argv 2]
set password [lindex $argv 3]
set src_file [lindex $argv 4]
set dest_file [lindex $argv 5]

spawn ssh $username@$host -p60139 systemctl stop boxkeeper
expect {
    "*yes/no" { send "yes\r"; exp_continue }
    "*password:" { send "$password\r" }
}
expect eof

spawn scp -P $port $src_file $username@$host:$dest_file
expect {
 "(yes/no)?" {
   send "yes\n"
   expect "*assword:" { send "$password\n"}
  }
  "*assword:" {
   send "$password\n"
  }
}
expect "100%"
expect eof

spawn ssh $username@$host -p60139 systemctl start boxkeeper
expect {
    "*yes/no" { send "yes\r"; exp_continue }
    "*password:" { send "$password\r" }
}
expect eof
posted @ 2022-05-25 08:39  jiftle  阅读(90)  评论(0编辑  收藏  举报