From 18cdbf17334a0b47e7aaaabf88247ec0341e0e91 Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Wed, 29 Sep 2010 00:36:45 -0700 Subject: Raise an error if command results in error. --- lognotify.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lognotify.rb b/lognotify.rb index 0f05bc9..e72d8f6 100755 --- a/lognotify.rb +++ b/lognotify.rb @@ -24,6 +24,7 @@ # and appended to the cached log. require 'ftools' +require 'open3' # Global settings. CACHE_DIR="~/.cache/lognotify" @@ -75,8 +76,14 @@ end def retrieve_lines conf, lines command = "cat #{conf[:path]}" command << " | sed '1,#{lines}d'" unless lines.zero? + command = "ssh #{conf[:hostname]} \"#{command}\"" - return %x[ssh #{conf[:hostname]} "#{command}"] + Open3.popen3(command) do |stdin, stdout, stderr| + # Raise an error if any part of the command resulted in an error. + raise stderr.gets unless stderr.eof? + + return stdout.gets.to_s + end end # Append new lines to cached log. -- cgit v1.2.3-70-g09d2