Linux automatically upload files to the server and extract the script

My blog is a separate front and rear end, after each new code needs to manually compress the file, and then use scp uploaded to the server nginx working directory, and unpack, one to one to too much trouble.

So we can expect to use this tool.

code show as below.

#!/usr/bin/expect
# 使用scp上传
spawn scp /home/project/html/Blog/Blog.tar.gz root@ip:/var/www/html
#等待带有password字样,并输入密码
expect "*password*" {send "密码\r"}
#退出
expect eof
#ssh连接服务器
spawn ssh root@ip
#等待带有password字样,并输入密码
expect "*password*" {send "密码\r"}
#输入密码后进入网站存放目录,并解压
expect "*#" {
    send "cd /var/www/html \r"
    send "tar -zxvf Blog.tar.gz \r"
}
#退出
expect eof

Upload decompression at one go.

Published 42 original articles · won praise 7 · views 7748

Guess you like

Origin blog.csdn.net/HouXinLin_CSDN/article/details/104249012