python - 退出代码:fabric2 在执行远程 ssh 命令时出现 127
问题描述
我在使用fabric2命令模块时遇到了一个奇怪的行为。这些命令就像一个魅力:
connect = Connection(host=h, user=u ,connect_kwargs={"password":p})
connect.run('mkdir temp_streaming')
connect.put(m, "temp_streaming/mapper.py")
connect.put(r, "temp_streaming/reducer.py")
但说到这个:
input_path = input("Please choose the input of your program (on your HDFS File System) ")
output_path = input("Please choose a name for your output folder ")
main_command = str('yarn jar '+ jar_path+' -files mapper.py,reducer.py -mapper temp_streaming/mapper.py -reducer temp_streaming/reducer.py -input '+ input_path + ' -output '+ output_path)
connect.run(main_command)
我收到这个错误,我无法弄清楚:
bash: yarn: command not found
Traceback (most recent call last):
File "__main.py__", line 77, in <module>
main()
File "__main.py__", line 65, in main
RunMapReduce(mapper, reducer, jar_path)
File "__main.py__", line 46, in RunMapReduce
connect.run(main_command)
File "<decorator-gen-3>", line 2, in run
File "/usr/local/lib/python3.5/dist-packages/fabric2/connection.py", line 30, in opens
return method(self, *args, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/fabric2/connection.py", line 586, in run
return self._run(runner, command, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/invoke/context.py", line 100, in _run
return runner.run(command, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/invoke/runners.py", line 268, in run
return self._run_body(command, **kwargs)
File "/usr/local/lib/python3.5/dist-packages/invoke/runners.py", line 401, in _run_body
raise UnexpectedExit(result)
invoke.exceptions.UnexpectedExit: Encountered a bad command exit code!
Command: 'yarn jar /home/hadoop/hadoop/share/hadoop/tools/lib/hadoop-streaming-2.8.4.jar -files mapper.py,reducer.py -mapper temp_streaming/mapper.py -reducer temp_streaming/reducer.py -input /books/kafka_metamorphosis.txt -output /test'
Exit code: 127
Stdout: already printed
Stderr: already printed
当我使用 ssh 直接登录服务器并运行它时,即使这个 bash 命令有效,它也好像远程服务器不知道yarn命令。在我看来,它与这个库有关,但我无法用文档解决我的问题。
解决方案
我也遇到了这个问题:原来 Fabric 运行的 SSH 是一个非交互式 shell。$PATH
包含 bin 路径的变量yarn
设置为/etc/profile
or ~/.bash_profile
, or ~/.bashrc
,这些都没有得到来源。
这是链接,以及一些解决方案。
就个人而言,我不喜欢玩这些文件 => 我刚刚所做的(在偶然发现此链接之前)是我使用了二进制文件的完整路径:/usr/bin/yarn [the rest of your command]
推荐阅读
- python - Website login not working with selenium/python?
- sql-server - Difference between begin transaction and begin atomic
- c# - XML De/Serialization : How to define different name for same property of different instance of the class
- django - daphne 在主管中运行返回错误 django.core.exceptions.ImproperlyConfigured
- java - crash screen customization with react-native-exception-handler
- android-studio - Android Studio 2020.3.1 x64 无法启动
- puppeteer - 获取“TimeoutError:等待 Page.printToPDF 失败”时如何增加 pupetteer 的 Page.pdf 的超时?
- jmeter - 在 Jmeter 响应中移动对象
- asp.net - asp.NET 4.8 WebRequest 错误,显示“底层连接已关闭:发送时发生意外错误。”
- authentication - 我如何知道它是新用户还是在使用 Google 登录之前已经登录?