summaryrefslogtreecommitdiff
path: root/lognotify.rb
diff options
context:
space:
mode:
authorDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-28 04:37:33 -0700
committerDavid Vazgenovich Shakaryan <dvshakaryan@gmail.com>2010-09-28 04:37:33 -0700
commitc6238e95e859819785e4207eaccc8b19097ca32d (patch)
tree547048ce2ad32a5b67a993266e1cf54bdd60da86 /lognotify.rb
parent2e56f9c8e170e2883a5577c69542d2f03de8cfb8 (diff)
downloadlognotify-c6238e95e859819785e4207eaccc8b19097ca32d.tar.gz
lognotify-c6238e95e859819785e4207eaccc8b19097ca32d.tar.xz
Add code to acquire new lines over SSH.
Diffstat (limited to 'lognotify.rb')
-rwxr-xr-xlognotify.rb22
1 files changed, 20 insertions, 2 deletions
diff --git a/lognotify.rb b/lognotify.rb
index 9d26836..b5d1977 100755
--- a/lognotify.rb
+++ b/lognotify.rb
@@ -35,13 +35,31 @@ def parse identifier
return conf
end
+def determine_size identifier
+ file = File.expand_path(CACHE_DIR + '/' + identifier + '.log')
+ return File.open(file).readlines.length
+end
+
+def acquire_new_lines conf, lines
+ command = 'cat ' + conf[:log_path]
+ command << " | sed '1," + lines.to_s + "d'" if lines > 0
+ return %x[ssh #{conf[:ssh_hostname]} "#{command}"]
+end
+
# Output all messages immediately, as opposed to buffering.
STDOUT.sync = true
# Test code...
ARGV.each do |identifier|
+ conf = parse(identifier)
+
print '* Determining number of lines in cached log... '
- file = File.expand_path(CACHE_DIR + '/' + identifier + '.log')
- lines = File.open(file).readlines.length
+ lines = determine_size(identifier)
puts lines
+
+ print '* Acquiring new lines via SSH... '
+ logappend = acquire_new_lines(conf, lines)
+ puts 'Done'
+ puts
+ puts logappend
end