Guest User

Untitled

a guest
Mar 14th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2.  
  3. require 'sendgmail.rb'
  4. require 'yaml'
  5.  
  6. @log_dir = "/path/to/log"
  7. @channels = %w{#xxxxx@freenode #xxxxx@twitter}
  8. @file_name = Time.now.strftime("%Y.%m.%d.txt")
  9. @keywords = "key1|key2|key3"
  10. @send_mail_address = "xxxxxx@gmail.com"
  11. @to_mail_address = "xxxx@xxxx.ne.jp"
  12. @mail_title = "IRC REPLY"
  13. @user = "user"
  14. @pass = "pass"
  15. @save_file = "readLabel.yaml"
  16.  
  17. replys = []
  18. readLabel = YAML.load_file(@save_file)
  19.  
  20. @channels.each do |channel|
  21.  
  22. line_number = 0
  23. open("#{@log_dir}/#{channel}/#{@file_name}").each_line { |line|
  24. line_number += 1
  25. next if !readLabel[channel].nil? && line_number <= readLabel[channel]
  26. replys << line if line =~ /^[\d]{2}:[\d]{2}:[\d]{2}[\s]+[<].+?[>].+?(#{@keywords})/
  27. }
  28. readLabel[channel] = line_number
  29.  
  30. end
  31.  
  32. fw = File.open(@save_file,'w+')
  33. fw.puts readLabel.to_yaml
  34. fw.close
  35.  
  36. if !replys.empty?s
  37. sendgmail(@send_mail_address, [@to_mail_address], @mail_title, replys.join, @user, @pass)
  38. end
Add Comment
Please, Sign In to add comment