【问题标题】:"readOnly" and other symbols not found when executing shell script remotely远程执行 shell 脚本时找不到“readOnly”和其他符号
【发布时间】:2015-05-02 20:54:14
【问题描述】:

我在下面有一个简单的 shell 脚本:

#!/bin/bash
# Hadoop Clear
readOnly hadoop = /opt/hadoop/bin/hadoop
hadoop fs -rm -r /

当我在同一台机器的终端上运行脚本时,一切正常,没有错误。 现在,我想远程调用这个脚本。所以从我的java 程序中,我对服务器执行ssh,并调用脚本: sh <full Path to script>.

我收到一条错误消息:

clearHadoop.sh: readOnly: not found
clearHadoop.sh: hadoop not found

知道为什么会这样吗?

【问题讨论】:

  • 我首先在机器 A 上运行 shell 脚本。它可以工作。然后我在同一台机器A上运行相同的脚本,但我从机器B调用脚本。A中有hadoop,readOnly是一个shell关键字,所以我认为这不是问题

标签: java linux shell unix ssh


【解决方案1】:

readonly 是 bash 关键字,而不是 readOnly

这听起来像是您在仅影响交互式会话(因此不影响远程会话)的 shell 初始化文件中将 hadoop 的路径添加到 $PATH

还有sh 不是/bin/bash。如果你想要bash 使用bash 而不是sh

【讨论】:

  • 我需要在哪里添加路径才能在远程会话中启用它?
  • 信息会有所帮助,但我通过提供 hadoop 的完整路径暂时解决了这个问题。
  • @Aneesh 你现在在哪里添加它? Shell init 文件理解起来有些复杂。在 stackexchange 网站上有一些关于它们的非常好的答案(但我现在很难找到它们)。
【解决方案2】:

您的 readOnly 行中有错字。至少我刚刚尝试过的 bash 抱怨 readOnly

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-10-24
    • 1970-01-01
    • 2015-07-22
    • 1970-01-01
    • 2021-12-29
    • 2019-10-26
    • 2016-05-27
    • 1970-01-01
    相关资源
    最近更新 更多