summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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.