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
  • 相关阅读:
    asp.net获取服务端和客户端信息
    ASP.NET 中JSON 的序列化和反序列化
    Asp.net TextBox常规输入验证
    ADO.NET中的五个主要对象
    .Net一般处理程序来实现用户名的验证
    .net获取当前网址url(各种参数值)
    hdu-1941 Find the Shortest Common Superstring
    字典树的动态与静态模板
    模板 Dijkstra+链式前向星+堆优化(非原创)
    基础深搜小结
  • 原文地址:https://www.cnblogs.com/yangxusun9/p/12404899.html
Copyright © 2011-2022 走看看