diff options
author | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-09-28 09:57:20 -0700 |
---|---|---|
committer | David Vazgenovich Shakaryan <dvshakaryan@gmail.com> | 2010-09-28 09:57:20 -0700 |
commit | 05dfcea4e86766ec090be5190482274ccded9bfb (patch) | |
tree | 0bd238d1e58f1f6deb2e7b0b058d6e4abf2c62ee | |
parent | c6238e95e859819785e4207eaccc8b19097ca32d (diff) | |
download | lognotify-05dfcea4e86766ec090be5190482274ccded9bfb.tar.gz lognotify-05dfcea4e86766ec090be5190482274ccded9bfb.tar.xz |
Minor changes and improvements.
-rwxr-xr-x | lognotify.rb | 27 |
1 files changed, 16 insertions, 11 deletions
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 |