忘记密码   免费注册 查看新帖 |

ChinaUnix.net

  平台 论坛 博客 文库 频道自动化运维 虚拟化 储存备份 C/C++ PHP MySQL 嵌入式 Linux系统
最近访问板块 发新帖
查看: 641 | 回复: 3

[其他] 关于ssh执行shell命令的问题 [复制链接]

论坛徽章:
0
发表于 2018-09-27 11:48 |显示全部楼层
本帖最后由 ighack 于 2018-09-27 12:37 编辑

我的shell文件是这样的
  1. ssh jzyctest@10.3.87.33 <<remotessh

  2. PIDS=$(ps ax | grep -i 'kafkaServer-gc' | grep java | grep -v grep | awk '{print $1}')

  3. if [ -z "$PIDS" ]; then
  4.   cd /opt/kafka_2.11-0.10.1.0/bin
  5.   ./kafka-server-start.sh -daemon ../config/server.properties

  6. fi
  7. exit

  8. remotessh


  9. ssh jzyctest@10.3.87.211 <<remotessh

  10. PIDS=$(ps ax | grep -i 'kafkaServer-gc' | grep java | grep -v grep | awk '{print $1}')

  11. if [ -z "$PIDS" ]; then
  12.   cd /opt/kafka_2.11-0.10.1.0/bin
  13.   ./kafka-server-start.sh -daemon ../config/server.properties
  14. fi
  15. exit

  16. remotessh

  17. ssh jzyctest@10.3.87.209 <<remotessh

  18. PIDS=$(ps ax | grep -i 'kafkaServer-gc' | grep java | grep -v grep | awk '{print $1}')

  19. if [ -z "$PIDS" ]; then
  20.   cd /opt/kafka_2.11-0.10.1.0/bin
  21.   ./kafka-server-start.sh -daemon ../config/server.properties
  22. fi
  23. exit

  24. remotessh

  25. echo done!
复制代码
第一段执行没报错,但第二,三段都报错

Pseudo-terminal will not be allocated because stdin is not a terminal.
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 3: 10687: command not found
Pseudo-terminal will not be allocated because stdin is not a terminal.
-bash: line 3: 10687: command not found
done!

我加了-tt以后的显示


  1. tcgetattr: Inappropriate ioctl for device
  2. Last login: Thu Sep 27 12:34:34 2018 from tester

  3. PIDS=21930

  4. if [ -z "" ]; then
  5.   cd /opt/kafka_2.11-0.10.1.0/bin
  6.   ./kafka-server-start.sh -daemon ../config/server.properties

  7. fi
  8. exit

  9. [jzyctest@tester ~]$
  10. [jzyctest@tester ~]$ PIDS=21930
  11. [jzyctest@tester ~]$
  12. [jzyctest@tester ~]$ if [ -z "" ]; then
  13. >   cd /opt/kafka_2.11-0.10.1.0/bin
  14. >   ./kafka-server-start.sh -daemon ../config/server.properties
  15. >
  16. > fi
  17. [jzyctest@tester bin]$ exit
  18. logout
  19. Connection to 10.3.87.33 closed.
  20. tcgetattr: Inappropriate ioctl for device

  21. PIDS=21930
  22. 22312

  23. if [ -z "" ]; then
  24.   cd /opt/kafka_2.11-0.10.1.0/bin
  25.   ./kafka-server-start.sh -daemon ../config/server.properties
  26. fi
  27. exit

  28. Last login: Thu Sep 27 12:34:35 2018 from tester
  29. [jzyctest@kafka-cluser02 ~]$
  30. [jzyctest@kafka-cluser02 ~]$ PIDS=21930
  31. [jzyctest@kafka-cluser02 ~]$ 22312
  32. -bash: 22312: command not found
  33. [jzyctest@kafka-cluser02 ~]$
  34. [jzyctest@kafka-cluser02 ~]$ if [ -z "" ]; then
  35. >   cd /opt/kafka_2.11-0.10.1.0/bin
  36. >   ./kafka-server-start.sh -daemon ../config/server.properties
  37. > fi
  38. [jzyctest@kafka-cluser02 bin]$ exit
  39. logout
  40. Connection to 10.3.87.211 closed.
  41. tcgetattr: Inappropriate ioctl for device
  42. Last login: Thu Sep 27 12:34:35 2018 from tester

  43. PIDS=21930
  44. 22312

  45. if [ -z "" ]; then
  46.   cd /opt/kafka_2.11-0.10.1.0/bin
  47.   ./kafka-server-start.sh -daemon ../config/server.properties
  48. fi
  49. exit

  50. [jzyctest@Kafka-cluster-01 ~]$
  51. [jzyctest@Kafka-cluster-01 ~]$ PIDS=21930
  52. [jzyctest@Kafka-cluster-01 ~]$ 22312
  53. -bash: 22312: command not found
  54. [jzyctest@Kafka-cluster-01 ~]$
  55. [jzyctest@Kafka-cluster-01 ~]$ if [ -z "" ]; then
  56. >   cd /opt/kafka_2.11-0.10.1.0/bin
  57. >   ./kafka-server-start.sh -daemon ../config/server.properties
  58. > fi
  59. [jzyctest@Kafka-cluster-01 bin]$ exit
  60. logout
  61. Connection to 10.3.87.209 closed.
  62. done!
  63. jzyctest@tester:/opt#
复制代码



论坛徽章:
0
发表于 2018-09-28 16:43 |显示全部楼层
use multiple -t

ssh -t -t hostname << EOF
your_command
EOF

论坛徽章:
0
发表于 2018-10-04 09:04 |显示全部楼层
我加了tt
但出现这个错误我不理解
-bash: line 3: 10687: command not found

论坛徽章:
0
发表于 2018-10-08 11:08 |显示全部楼层
ssh -Tq 用这个
您需要登录后才可以回帖 登录 | 注册

本版积分规则

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号 北京市公安局海淀分局网监中心备案编号:11010802020122
广播电视节目制作经营许可证(京) 字第1234号 中国互联网协会会员  联系我们:wangnan@it168.com
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP