# How to show output of shell script on console?

**URL:** <https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616>\
**Category:** Chef Infra (archive)\
**Created:** [May 26, 2015, 8:44pm UTC](https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616 "2015-05-26T20:44:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chris\_F](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@Chris\_F](https://discourse.chef.io/u/Chris_F)\
**Post date:** [May 26, 2015, 8:44pm UTC](https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616/1 "2015-05-26T20:44:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Fitzwater\_Brian\_K\_CT](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/fitzwater_brian_k_ct/32/45_2.png) [@Fitzwater\_Brian\_K\_CT](https://discourse.chef.io/u/Fitzwater_Brian_K_CT)\
**Post date:** [May 26, 2015, 9:16pm UTC](https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616/2 "2015-05-26T21:16:11Z")

</div>

You could use Mixlib::ShellOut.

> **[chef/mixlib-shellout](https://github.com/chef/mixlib-shellout)**
>
> mixlib-shellout - mixin library for subprocess management, output collection

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](mailto:Chris.Fouts@Sensus.com)]  
Sent: Tuesday, May 26, 2015 4:45 PM  
To: [chef@lists.opscode.com](mailto: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

---

<div class="post-metadata">

**Author:** ![Chris\_F](https://avatars.discourse-cdn.com/v4/letter/c/fbc32d/32.png) [@Chris\_F](https://discourse.chef.io/u/Chris_F)\
**Post date:** [May 27, 2015, 9:51am UTC](https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616/3 "2015-05-27T09:51:49Z")

</div>

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](mailto:brian.k.fitzwater@uscis.dhs.gov)]  
Sent: Tuesday, May 26, 2015 5:16 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
Subject: [chef] RE: How to show output of shell script on console?

You could use Mixlib::ShellOut.

> **[chef/mixlib-shellout](https://github.com/chef/mixlib-shellout)**
>
> mixlib-shellout - mixin library for subprocess management, output collection

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](mailto:Chris.Fouts@Sensus.com)]  
Sent: Tuesday, May 26, 2015 4:45 PM  
To: [chef@lists.opscode.com](mailto:chef@lists.opscode.com)[mailto:chef@lists.opscode.com](mailto: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

---

<div class="post-metadata">

**Author:** ![Brandon\_Raabe](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.chef.io/brandon_raabe/32/40_2.png) [@Brandon\_Raabe](https://discourse.chef.io/u/Brandon_Raabe)\
**Post date:** [May 27, 2015, 3:27pm UTC](https://discourse.chef.io/t/how-to-show-output-of-shell-script-on-console/6616/4 "2015-05-27T15:27:14Z")

</div>

If you use the live\_stdout method I think you'll have what you're looking  
for.

```ruby
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

```

> <https://github.com/chef/mixlib-shellout/blob/master/lib/mixlib/shellout.rb#L60-L62>

> <https://github.com/chef/mixlib-shellout/blob/master/lib/mixlib/shellout.rb#L60-L62>

On Wed, May 27, 2015 at 2:52 AM Fouts, Chris [Chris.Fouts@sensus.com](mailto: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](mailto:brian.k.fitzwater@uscis.dhs.gov)]  
> _Sent:_ Tuesday, May 26, 2015 5:16 PM  
> _To:_ [chef@lists.opscode.com](mailto:chef@lists.opscode.com)  
> _Subject:_ [chef] RE: How to show output of shell script on console?
> 
> You could use Mixlib::ShellOut.
> 
> [GitHub - chef/mixlib-shellout: mixin library for subprocess management, output collection](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](mailto:Chris.Fouts@Sensus.com)  
> [Chris.Fouts@Sensus.com](mailto:Chris.Fouts@Sensus.com)]  
> _Sent:_ Tuesday, May 26, 2015 4:45 PM  
> _To:_ [chef@lists.opscode.com](mailto: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
