zoukankan      html  css  js  c++  java
  • ssh 主机地址 命令 显示 command not found 的解决方案

    #!/bin/bash
    source /etc/profile
    for host in hadoop102 hadoop103 hadoop104
    do
        echo ------------------- $host --------------
        ssh $host $@
    done

    此为集群间的群起脚本 ,调用时却发现

     

     出现问题的原因解析

    首先shell分为LoginShellNoLoginShell

    LoginShell: 登录后,提供了一个shell的bash界面,此时就属于loginshell

    NoLoginShell: 登录后,没有提供一个可以输入命令的bash界面!

    区别: 登录后执行脚本的顺序和脚本不同

     这种Login shell  执行脚本的顺序:
           1. /etc/profile       【全局profile文件;它定义了LoginUser的 PATH, USER, LOGNAME(登录使用者帐号)】
           2. /etc/profile.d/目录下的脚本
           3. ~/.bash_profile   【搜索命令的路径    ————- 登录级别 环境变量配置文件 】
           4. ~/.bashrc      【存储用户设定的别名和函数 ———- shell级别 环境变量配置文件】
           5. /etc/bashrc     【全局bashrc文件; 它主要定义一些 Function 和 Alias;更改/etc/bashrc会影响到所有用户,由root用户管理。】
      Non-Login shell
        登录终端后,使用ssh 登录 其他机器!
           非登录shell指的是,不需要输入用户名密码的shell,如图形下 右键terminal,或ctrl+shift+T打开的shell
         这种Non-Login shell 执行登录脚本的顺序: 
           1. ~/.bashrc
           2. /etc/bashrc
           3. /etc/profile.d/目录下的脚本

    脚本这种方式明显是 NologinShell。

    而我的JAVA_HOME是配置在/etc/profile中,这种启动模式根本不会去调用,所以需要在上面的脚本中添加上一句

    source /etc/profile

    #!/bin/bash
    source /etc/profile
    for host in hadoop102 hadoop103 hadoop104
    do
        echo ------------------- $host --------------
        ssh $host "source /etc/profile;$@"
    done

    解决方案二:

    cat /etc/profile >> ~/.bashrc
  • 相关阅读:
    随机数
    质数
    猜数
    失败
    判断质数
    2019.7.21记录
    9*9乘法表
    小人
    奔跑的字母

  • 原文地址:https://www.cnblogs.com/yangxusun9/p/12404899.html
Copyright © 2011-2022 走看看