From c6238e95e859819785e4207eaccc8b19097ca32d Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 28 Sep 2010 04:37:33 -0700 Subject: Add code to acquire new lines over SSH. --- lognotify.rb | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'lognotify.rb') 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 -- cgit v1.2.3-70-g09d2