summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-29 00:36:45 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-29 00:36:45 -0700
commit18cdbf17334a0b47e7aaaabf88247ec0341e0e91 (patch)
treea369a7c26c2f2a39ce2c0b37ad6b83a9a352e497
parent899ee539c5578b1f2fcbb34df2bb245ac90fbb38 (diff)
downloadlognotify-18cdbf17334a0b47e7aaaabf88247ec0341e0e91.tar.gz
lognotify-18cdbf17334a0b47e7aaaabf88247ec0341e0e91.tar.xz
Raise an error if command results in error.
-rwxr-xr-xlognotify.rb9
1 files changed, 8 insertions, 1 deletions
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.