Linux自动上传文件到服务器并解压脚本

我的博客是前后端分离式,每次新增代码后需要手动压缩文件,之后使用scp上传到服务器中nginx的工作目录,并解压,一来一去太麻烦。

所以可以使用expect​这个工具。

代码如下。

#!/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

上传解压一气呵成.

发布了42 篇原创文章 · 获赞 7 · 访问量 7748

猜你喜欢

转载自blog.csdn.net/HouXinLin_CSDN/article/details/104249012
今日推荐