Skip to content

Instantly share code, notes, and snippets.

@mvidner
Last active November 30, 2017 08:23
Show Gist options
  • Select an option

  • Save mvidner/acb5a1111e47628391909b1c468c0202 to your computer and use it in GitHub Desktop.

Select an option

Save mvidner/acb5a1111e47628391909b1c468c0202 to your computer and use it in GitHub Desktop.
Cheetah using the YaST log
#!/usr/bin/ruby
require "cheetah"
require "yast"
Cheetah.run("ls", "-la", "/var/lib/empty", logger: Yast::Y2Logger.instance)
# another way: "log" becomes a shortcut for Yast::Y2Logger.instance
include Yast::Logger
begin
Cheetah.run("ls", "-la", "/no/such/file", logger: log)
rescue Cheetah::ExecutionFailed
log.error "Not there I guess"
end
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:158 Executing "ls -la /var/lib/empty".
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:206 Standard output: total 8
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:206 Standard output: drwxr-xr-x 2 root root 4096 May 10 2017 .
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:206 Standard output: drwxr-xr-x 96 root root 4096 Aug 15 10:04 ..
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:178 Status: 0
2017-11-30 08:57:50 <1> hal.example.org(4291) [Ruby] lib/cheetah.rb:158 Executing "ls -la /no/such/file".
2017-11-30 08:57:50 <3> hal.example.org(4291) [Ruby] lib/cheetah.rb:206 Error output: ls: cannot access '/no/such/file': No such file or directory
2017-11-30 08:57:50 <3> hal.example.org(4291) [Ruby] lib/cheetah.rb:178 Status: 2
2017-11-30 08:57:50 <3> hal.example.org(4291) [Ruby] snippets/cheetah-y2log.rb:13 Not there I guess
@mvidner

mvidner commented Nov 30, 2017

Copy link
Copy Markdown
Author

So, this is actually a reinvention of a (previously undocumented) wheel:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment