From 05dfcea4e86766ec090be5190482274ccded9bfb Mon Sep 17 00:00:00 2001 From: David Vazgenovich Shakaryan Date: Tue, 28 Sep 2010 09:57:20 -0700 Subject: Minor changes and improvements. --- lognotify.rb | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'lognotify.rb') diff --git a/lognotify.rb b/lognotify.rb index b5d1977..0b6b030 100755 --- a/lognotify.rb +++ b/lognotify.rb @@ -35,31 +35,36 @@ def parse identifier return conf end -def determine_size identifier +# Count lines in cached log. +def count_lines 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}"] +# Retrieve new lines via SSH. +def retrieve_lines path, lines, hostname + command = "cat #{path}" + command << " | sed '1,#{lines}d'" if lines > 0 + + return %x[ssh #{hostname} "#{command}"] end # Output all messages immediately, as opposed to buffering. STDOUT.sync = true -# Test code... +# Treat each argument as a log identifier. ARGV.each do |identifier| conf = parse(identifier) - print '* Determining number of lines in cached log... ' - lines = determine_size(identifier) + print '* Counting lines in cached log... ' + lines = count_lines(identifier) puts lines - print '* Acquiring new lines via SSH... ' - logappend = acquire_new_lines(conf, lines) + print '* Retrieving new lines via SSH... ' + newlines = retrieve_lines(conf[:log_path], lines, conf[:ssh_hostname]) puts 'Done' + + puts '* Number of new lines: ' + newlines.lines.count.to_s puts - puts logappend + puts newlines end -- cgit v1.2.3-70-g09d2