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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章