How to show output of shell script on console?


#1

I have a ruby_block that just executes a shell script. How do I get Chef to echo its output to the console? Will using a bash resource do it?

Chris


#2

You could use Mixlib::ShellOut.

I use Chef::Log to output to the console, for example:

find = Mixlib::ShellOut.new(“find . -name ‘*.rb’”)
find.run_command
Chef::Log.info “Find results: #{find.stdout}”

–fitz

From: Fouts, Chris [mailto:Chris.Fouts@Sensus.com]
Sent: Tuesday, May 26, 2015 4:45 PM
To: chef@lists.opscode.com
Subject: [chef] How to show output of shell script on console?

I have a ruby_block that just executes a shell script. How do I get Chef to echo its output to the console? Will using a bash resource do it?

Chris


#3

Thanks, I’ll try this. However, your snippet “looks” like it will output the result of the command “after” the command has been executed? I’m interested in echoing the output as the shell script is executing.

Chris

From: Fitzwater, Brian K (CTR) [mailto:brian.k.fitzwater@uscis.dhs.gov]
Sent: Tuesday, May 26, 2015 5:16 PM
To: chef@lists.opscode.com
Subject: [chef] RE: How to show output of shell script on console?

You could use Mixlib::ShellOut.

I use Chef::Log to output to the console, for example:

find = Mixlib::ShellOut.new(“find . -name ‘*.rb’”)
find.run_command
Chef::Log.info “Find results: #{find.stdout}”

–fitz

From: Fouts, Chris [mailto:Chris.Fouts@Sensus.com]
Sent: Tuesday, May 26, 2015 4:45 PM
To: chef@lists.opscode.commailto:chef@lists.opscode.com
Subject: [chef] How to show output of shell script on console?

I have a ruby_block that just executes a shell script. How do I get Chef to echo its output to the console? Will using a bash resource do it?

Chris


#4

If you use the live_stdout method I think you’ll have what you’re looking
for.

ruby_block 'live stdout' do
  block do
    require 'mixlib/shellout'
    cmd = Mixlib::ShellOut.new('for i in {1..5}; do echo $(date); sleep 1;
done')
    cmd.live_stdout = $stdout
    cmd.run_command
  end
end


On Wed, May 27, 2015 at 2:52 AM Fouts, Chris Chris.Fouts@sensus.com wrote:

Thanks, I’ll try this. However, your snippet “looks” like it will output
the result of the command “after” the command has been executed? I’m
interested in echoing the output as the shell script is executing.

Chris

From: Fitzwater, Brian K (CTR) [mailto:brian.k.fitzwater@uscis.dhs.gov]
Sent: Tuesday, May 26, 2015 5:16 PM
To: chef@lists.opscode.com
Subject: [chef] RE: How to show output of shell script on console?

You could use Mixlib::ShellOut.

https://github.com/chef/mixlib-shellout

I use Chef::Log to output to the console, for example:

find = Mixlib::ShellOut.new(“find . -name ‘*.rb’”)

find.run_command

Chef::Log.info “Find results: #{find.stdout}”

–fitz

From: Fouts, Chris [mailto:Chris.Fouts@Sensus.com
Chris.Fouts@Sensus.com]
Sent: Tuesday, May 26, 2015 4:45 PM
To: chef@lists.opscode.com
Subject: [chef] How to show output of shell script on console?

I have a ruby_block that just executes a shell script. How do I get Chef
to echo its output to the console? Will using a bash resource do it?

Chris