2019独角兽企业重金招聘Python工程师标准>>>

0、前言

场景描述:现有192.168.5.51~192.168.5.55需要发布不同观点项目,希望达到的效果是ssh登录到192.168.5.117执行一个脚本一键发布所有项目到51,52,53,54,55.

1、remote.sh

此脚本放置在本地终端


#!/bin/sh
/usr/bin/expect <<EOF
#!/usr/bin/expectif { "$1" == "174" } {set timeout -1spawn /usr/local/nginx/sbin/remote1.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.174's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "soa-55" } {spawn /usr/local/nginx/sbin/remote_soa_55.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.55's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "soa-54" } {set timeout -1spawn /usr/local/nginx/sbin/remote_soa_54.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.54's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "api" } {set timeout -1spawn /usr/local/nginx/sbin/remote_api.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.51's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "cos-63" } {set timeout -1spawn /usr/local/nginx/sbin/remote_cos_63.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.63's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "cos-cms-53" } {set timeout -1spawn /usr/local/nginx/sbin/remote_cos_cms_53.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.53's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "cms-52" } {set timeout -1spawn /usr/local/nginx/sbin/remote_cms_52.shexpect {"Are you sure you want to continue connecting (yes/no)?" {send "yes\r";exp_continue;}"root@192.168.5.52's password:" {send "passowrd\r";exp_continue;}}
}if { "$1" == "all" } {
}EOF

2、remote_api.sh

调用的脚本

#!/bin/bash
set timeout 1000
/usr/bin/ssh root@192.168.5.174  " rm -rf  /usr/local/tomcat_9090/deploy/*.war"
scp /usr/local/nginx/sbin/code-soa.war  root@192.168.5.174:/usr/local/tomcat_9090/deploy/
/usr/bin/ssh root@192.168.5.174  "source /etc/profile"
/usr/bin/ssh root@192.168.5.174  "sh /usr/local/tomcat_9090/deploy/remote_deploy.sh"

3、deploy_remote.sh

放在目标机器的脚本

rm  /usr/local/tomcat-cms/webapps/code-* -rf;
kill -9   `netstat -tpln|grep ":9090"|awk '{printf $7}'|cut -d/ -f1`;
cp /usr/local/tomcat-cms/deploy/code-cms.war /usr/local/tomcat-cms/webapps/
source /etc/profile
sh /usr/local/tomcat-cms/bin/startup.sh

4、deploy_all.sh

#!/bin/bash
sh remote117.sh api;
sh remote117.sh soa-55;
sh remote117.sh soa-54;
sh remote117.sh cos-63;
sh remote117.sh cos-cms-53;
sh remote117.sh cms-52;

5、执行效果

6、思考

既然可以一键发布,那么是否可以做到从svn下载下代码后自动构建maven包然后一键部署到tomcat。

梯子

转载于:https://my.oschina.net/fengshuzi/blog/673535

expect自动登录以及远程脚本执行相关推荐

  1. 自动登录过BSO脚本 ( by quqi99 )

    自动登录过BSO脚本 ( by quqi99 ) 作者:张华  发表于:2012-05-07 版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http:// ...

  2. 中国电信数字中南智慧网自动登录油猴脚本

    中国电信数字中南智慧网自动登录油猴脚本 每次登陆校园网都要输入账号密码再点登陆,于是想自己编写一个油猴脚本自动登录.今天花了半个小时把脚本做出来了,写一篇教程帮助大家. 首先在浏览器上安装油猴插件,推 ...

  3. linux expect自动登录ssh,ftp

    expect是一种能够按照脚本内容里面设定的方式与交互式程序进行"会话"的程序.根据脚本内容,Expect可以知道程序会提示或反馈什么内容以及 什么是正确的应答.它是一种可以提供& ...

  4. Linux系列:Ubuntu/fedora实用小技巧—禁止自动锁屏、设置免密码自动登录、免密码执行sudo操作...

    首先声明:该文虽以Ubuntu 13.04为例,同样适用于Fedora 17(已测试),但在较低版本的Ubuntu下可能有所差异,具体看后面的注意事项. 技巧目录: 解决Ubuntu下每隔几分钟自动锁 ...

  5. ssh 远程脚本执行 java: command not found

    ssh 远程主机脚本执行.执行 java -version,报如题错误 [root@doris-fe-01 module]# ./install.sh "java -version &quo ...

  6. linux锁屏自动登录,Linux系列:Ubuntu/fedora实用小技巧—禁止自动锁屏、设置免密码自动登录、免密码执行sudo操作...

    首先声明:该文虽以Ubuntu 13.04为例,同样适用于Fedora 17(已测试),但在较低版本的Ubuntu下可能有所差异,具体看后面的注意事项. 技巧目录: 解决Ubuntu下每隔几分钟自动锁 ...

  7. python自动登录校园网_python 脚本自动登陆校园网

    学校的校园网每次重开电脑时都要重新打开浏览器进行网页登录,繁琐的操作比较麻烦,于是便写了个python的脚本进行自动登录,下面说下具体的操作过程: 1. 方法说明 博主采用的python的 reque ...

  8. 批量自动登录Windows远程桌面

    PS C:\Users\user> cmdkey 创建,显示和删除保存的用户名和密码. 此命令的语法为: CMDKEY [{/add | /generic}:targetname {/smart ...

  9. linux脚本expect自动登录,SHELL脚本:利用expect完成SSH自动登录

    有个业务需求,需要在服务器上安装一个Agent,安装Agent其实很简单,但是顶不住服务器数量太多,所以不可能一台台的登上去安装,所以写了个脚本可以实现批量自动化安装 1.脚本实现的功能 根据提供的I ...

  10. Linux使用expect自动登录,linux中使用expect实现自动登录(示例代码)

    在实际生产使用中,比如执行批量操作时,我们不想创建ssh认证,需要使用到密码登录或者链接,此时可以使用expect来操作自动添加password: 在centos系统上expect默认是没有安装的,所 ...

最新文章

  1. Spring 体系常用项目一览
  2. python的用途-请问在python中的% 是什么意思, 起到什么作用?
  3. Dokcer容器实战之部署论坛
  4. avue 文字点击 弹窗_经验 | UI设计师必懂的App弹窗设计方法
  5. Android UI(三)SlidingMenu实现滑动菜单(详细 官方)
  6. java 中 Object XML 互转,最终选择Xstream
  7. word List40
  8. idea的maven project消失解决方案
  9. C++ 读取单个字符
  10. 【华为云技术分享】【DevCloud · 敏捷智库】如何利用核心概念解决估算常见问题
  11. 【MySQL】MySQL 8报错 Unknown initial character set index 255 received from server. Initial client char
  12. Spring源码系列:BeanDefinition载入(下)
  13. 计算机的原码, 反码和补码
  14. python 顺序遍历文件夹下的文件
  15. 微软商店下载的python_Python 登录微软 Win10 应用商店
  16. oppo计算机找不到,oppo手机照片在电脑显示不出来怎么办啊
  17. python储物柜难题_转角那1㎡不做储物间?太浪费了!好好利用还解决收纳难题...
  18. Linux:冯诺伊曼体系结构 | 操作系统 | 显卡 | 主板
  19. send_nsca passive monitor setup notes
  20. HTML中的表格及样式的设置

热门文章

  1. Detours信息泄漏漏洞
  2. Java基础String类
  3. SQL查询最近几年、几月的数据
  4. react-native 适配问题
  5. C语言 二维数组(指针)动态分配和释放(转)
  6. appium问题解决
  7. react-踩坑记录——swiper报错!
  8. iOS开发——策略模式
  9. 生成验证码封装(新版)
  10. 【转】Java多线程面试问题集锦