本文最后更新于:2020年5月13日 下午

由于需要同步linux两端的文件,写了一个同步脚本!(此脚本也可用于vps静态部署hexo)。

#! /bin/sh

#删除远程服务器文件
deleteblog(){
expect -c "
		spawn ssh -i /root/.ssh/id_rsa1 root@xxx.xxx.xxx.xxx rm -fr /var/www/*
		expect {
               yes/no { send \"yes\r\"; exp_continue }
               passphrase* { send \"123456\r\" } #  123456 为秘钥密码
			   { send \"exit\r\" }
           };
		expect eof				
       "	   
}
#将文件同步到远程服务器
sendblog(){
expect -c "		   
           set timeout -1
           spawn scp -i /root/.ssh/id_rsa1 /date/dingblog.tar.gz  root@xxx.xxx.xxx.xxx:/var/www/
           expect {
               yes/no { send \"yes\r\"; exp_continue }
               passphrase* { send \"123456\r\" } #  123456 为秘钥密码
			   { send \"exit\r\" }
           };
           expect eof;
       "	   
}

#解压远程服务器文件
tarblog(){
expect -c "		   
           spawn ssh -i /root/.ssh/id_rsa1 root@xxx.xxx.xxx.xxx tar zxvf /var/www/dingblog.tar.gz -C /var/www/
           expect {
               yes/no { send \"yes\r\"; exp_continue }
               passphrase* { send \"123456\r\" } #  123456 为秘钥密码
			   { send \"exit\r\" }
           };
           expect eof;
       "	   
}

deleteblog
sendblog
tarblog

本博客所有文章除特别声明外,均采用 CC BY-SA 3.0协议 。转载请注明出处!

吉比特 wo-27s 光猫获取超密 下一篇