bash - 如何通过 Chef 运行 sh 脚本并显示 echo 输出
问题描述
我遇到了 Chef 和 sh 脚本的问题。我的 sh 脚本做了一些事情,对于每一步,它都会回显一条消息,表明某事是否成功完成。我想在 Chef 中运行此脚本,但它不起作用,我在日志中看不到任何内容,除了该脚本运行成功,这是不正确的。这是我的做法:
cookbook_file "/tmp/myLib.rpm" do
source "myLib.rpm"
mode '0775'
action :create
end
cookbook_file "/tmp/install.sh" do
source "install.sh"
mode '0755'
action :create
end
execute "installing my lib" do
command "sh /tmp/install.sh"
user 'root'
live_stream true
action :run
end
该脚本已成功完成,但在日志中我只能看到:
Loading cookbooks [security@0.0.1]
INFO: *** Chef 12.18.31 ***
INFO: Storing updated cookbooks/security/recipes/install-mylib.rb in the cache.
INFO: Storing updated cookbooks/security/metadata.rb in the cache.
INFO: Storing updated cookbooks/security/files/default/install.sh in the cache.
INFO: Storing updated cookbooks/security/files/default/myLib.rpm in the cache.
INFO: Processing cookbook_file[/tmp/myLib.rpm] action create (security::install-mylib line 1)
INFO: Processing cookbook_file[/tmp/install.sh] action create (security::install-mylib line 7)
INFO: cookbook_file[/tmp/install.sh] created file /tmp/install.sh
INFO: cookbook_file[/tmp/install.sh] updated file contents /tmp/install.sh
INFO: cookbook_file[/tmp/install.sh] mode changed to 755
INFO: Processing execute[installing my lib] action run (security::install-mylib line 13)
INFO: execute[installing my lib] ran successfully
我看不到来自 install.sh 的任何回声,并且此脚本的工作尚未完成。当我直接在机器上运行这个脚本时,一切正常。
任何帮助或想法将不胜感激。
解决方案
运行脚本的更好选择是使用脚本资源。尽管execute
资源也应该可以正常工作。
尝试使用script
资源运行脚本,如下所示:
script 'installing my lib' do
code '/tmp/install.sh'
user 'root'
interpreter 'bash'
action :run
end
推荐阅读
- android - 如何仅第一次收到意图以进入活动而不是配置更改?因为 getIntent 方法在 onCreate 方法中
- axios - 如何使用 axios 和 jsdom 从 cgv 网站获取 href 和 img 的包含
- javascript - 选中复选框时渲染不同的数据在我的反应项目中不起作用
- python - Django - AttributeError:模块'environ'没有属性'ENV'
- delphi - Microsoft WebView2 常青独立运行时不起作用
- java - 如何将值插入 JTextField?
- typescript - TypeScript中函数组合方法(链)的类型推断
- python-3.x - 在 Backtrader 中开设多个头寸
- r - 在 R 中查找 Iris 数据的协方差矩阵的问题
- php - Laravel 项目托管:文件上传和图片目录