Created
November 13, 2012 13:41
-
-
Save caok/4065819 to your computer and use it in GitHub Desktop.
发送ip地址和指定文件到某邮箱
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# | |
# ARGV[0] - msg | |
# ARGV[1] - mailto | |
# ARGV[2] - filename | |
require 'open-uri' | |
require 'rubygems' | |
require 'action_mailer' | |
ActionMailer::Base.smtp_settings = { | |
:address => 'smtp.163.com', | |
:port => 25, | |
:domain => '163.com', | |
:user_name => '[email protected]', | |
:password => 'xxxxxxx', | |
:authentication => 'login', | |
:enable_starttls_auto => true | |
} | |
class Notifer < ActionMailer::Base | |
default :from => '[email protected]' | |
def mailip(ip, msg, mailto, file) | |
attachments["#{file}"] = File.read("#{file}") | |
mail :to => mailto, :subject => "#{msg} ip is #{ip}" do |format| | |
format.text { render :text => ip} | |
end.deliver | |
end | |
end | |
open("http://checkip.dyn.com") do |f| | |
ip = f.read.slice /[0-9]+(\.[0-9]+){3}/ | |
# 要发送的文件的名称 | |
filename = "mysql-" + Time.now.strftime("%Y-%m-%d").to_s + ".sql.gz" | |
Notifer.mailip ip, ARGV[0], ARGV[1] || '[email protected]', ARGV[2] || filename | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment