1、远程机器编写脚本:
脚本名称为: /app/jboss/jboss-as/logs/ALL_SERVICE_STOP.sh
功能为:停止某个服务器某个目录下面的所有应用
#!/bin/bash path=/app/jboss/jboss-as/logs for instance in `ls $path|grep ".*.sh"|grep -v ALL_SERVICE_STOP.sh|xargs`;do cd $path ./$instance stop done
2、2台linux机器实现远程连接(jenkins服务器也是linux机器)
a、2台机执行ssh-keygen -t rsa ,生成id_rsa.pub文件
b、在jenkins linux执行命令:scp /home/xxxx/.ssh/id_rsa.pub [email protected]:/home/xxxx/.ssh/authorized_keys 输入密码登录
c、在jenkins linux再执行 scp /home/xxxx/.ssh/id_rsa.pub [email protected]:/home/xxxx/.ssh/authorized_keys 就不用输入密码登录了
3、jenkins构建执行shell 命令
ssh -t -p 22 [email protected] " /app/jboss/jboss-as/logs/ALL_SERVICE_STOP.sh"
就能执行远程命令了。
时间: 2024-10-24 20:13:00