免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1749 | 回复: 4
打印 上一主题 下一主题

[系统管理] ssh远程执行系统脚本出错,求大神 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-05-23 14:26 |只看该作者 |倒序浏览
./deploy_test.sh test ico.zip

脚本如下:
#!/bin/bash

#下载文件 本地保存路径
localdir=/home/test/deploy/src/
wget -c -N -T 10 $2 -O $localdir$2||exit 1
#远端备份目录
backupdir=/opt/backup

#test
test=(23
#m
m=192.168.16.


case $1 in
  test)
    for ip in ${test[*]}
     do
      #echo $ip
      scp -P22 $localdir$2 $m$ip:/tmp
      ssh -p22 -t $m$ip<<EOF
      #test远端存储目录
      testdes=/opt/vhosts/test
      #test远端程序目录
      testdesdir_list=`ls /opt/vhosts/ | grep test`
      #备份目录
      backupdir=/opt/backup
      if [ ! -d $backupdir ]
      then
         mkdir -p $backupdir && chown -R test:test $backupdir && chmod 775 $backupdir
      fi
      #提取所有test进程的id
      testid_list=`ps aux|grep test | grep -v grep|awk '{print $2}'`
      #提取所有test的tomcat进程的路径,必须tomcat名字都有OA,否则无法过滤
      testtomcatdir_list=`ps aux|grep test | grep -v grep | awk '{print $12}'| sed -e 's/.*=\(.*\)\/conf.*/\1/g'`
      for testid in $testid_list
      do   
          kill -9 $testid
      done  
      mv  $testdes/ROOT.war $backupdir/ROOT.war.`date +%Y%m%d-%T`
      for testdesdir in $testtomcatdir_list; do
          mv /tmp/$2  $testdesdir/ROOT.war
          rm -rf $testdesdir/ROOT
      done
      for testtomcatdir in $testtomcatdir_list
      do
          rm -rf $testtomcatdir/work/Catalina
          sh $testtomcatdir/bin/startup.sh && echo  update ok
      done
      source /etc/profile
      exit 0
EOF
      done
    ;;
esac

执行结果:

Address 192.168.16.238 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
ico.zip                                                                                           100% 5358KB   5.2MB/s   00:00   
+ ssh -p22 -t 192.168.16.238
++ ls /opt/vhosts/
++ grep test
++ ps aux
++ grep test
++ grep -v grep
++ awk '{print $2}'
++ ps aux
++ grep -v grep
++ grep test
++ awk '{print $12}'
++ sed -e 's/.*=\(.*\)\/conf.*/\1/g'
++ date +%Y%m%d-%T
Pseudo-terminal will not be allocated because stdin is not a terminal.
Address 192.168.16.238 maps to localhost, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
-bash: line 13: 28572: command not found
-bash: line 14: 28576: command not found
-bash: line 18: -x: command not found
-bash: line 19: -x: command not found
...
...

也就是从获取pid进程的时候,就出错了,错误当中显示的两个id也不是正确的, testid_list=`ps aux|grep test | grep -v grep|awk '{print $2}'` 命令在远程主机16.238上执行完全没有问题,求指教~~~为什么

论坛徽章:
54
2015亚冠之德黑兰石油
日期:2015-07-07 13:00:1615-16赛季CBA联赛之深圳
日期:2016-03-31 09:03:5415-16赛季CBA联赛之辽宁
日期:2016-05-09 20:38:15程序设计版块每日发帖之星
日期:2016-05-12 06:20:0015-16赛季CBA联赛之四川
日期:2016-05-13 15:19:4715-16赛季CBA联赛之福建
日期:2016-05-15 20:24:34每日论坛发贴之星
日期:2016-05-16 06:20:0015-16赛季CBA联赛之吉林
日期:2016-05-26 11:49:4715-16赛季CBA联赛之广东
日期:2016-05-26 13:49:18极客徽章
日期:2016-12-07 14:05:2315-16赛季CBA联赛之广夏
日期:2016-12-20 17:33:532017金鸡报晓
日期:2017-01-10 15:19:56
2 [报告]
发表于 2016-05-23 14:45 |只看该作者
这样一般是 $ 没有转义

论坛徽章:
0
3 [报告]
发表于 2016-05-23 14:50 |只看该作者
回复 2# haooooaaa

不是

   

论坛徽章:
0
4 [报告]
发表于 2016-05-23 22:13 |只看该作者
回复 1# zhaolianghz


    把"ssh -p22 -t $m$ip<<EOF"中的-t改成-T试试。

论坛徽章:
0
5 [报告]
发表于 2016-05-24 14:45 |只看该作者
回复 4# lll1985911

不行的
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP