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 @   jiftle  阅读(94)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 在鹅厂做java开发是什么体验
· 百万级群聊的设计实践
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
· 永远不要相信用户的输入:从 SQL 注入攻防看输入验证的重要性
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
历史上的今天:
2021-05-25 golang调用windows动态库dll方法
2018-05-25 在Eclipse中创建Maven多模块工程的例子
2018-05-25 我们为什么要进行模块化开发?
点击右上角即可分享
微信分享提示