Last active
December 4, 2015 06:34
-
-
Save jacoyutorius/22cebc02add0dc1fa5ad to your computer and use it in GitHub Desktop.
LinuxのSystemログをAWS CLI+RubyでS3にアップロードするスクリプトを書いた ref: http://qiita.com/jacoyutorius/items/64c04e540023d3d636f9
This file contains hidden or 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
| # 保存するログを格納しているディレクトリへのパス | |
| target_dir_path = [ | |
| "/var/log/httpd", | |
| "/var/log/mysql", | |
| "/var/log/messages" | |
| ] | |
| target_file_path = [ | |
| "/var/log/lastlog", | |
| "/var/log/maillog"," | |
| ""/var/log/yum-log", | |
| "/var/log/secure" | |
| ] | |
| # 保存するバケット名 | |
| target_bucket = "log-transfer" | |
| # プレフィクス(サーバー名) | |
| target_prefix = `hostname`.strip | |
| # upload directories | |
| target_dir_path.each do |path| | |
| next unless Dir.exist? path | |
| # "./test_dir" => "test_dir" | |
| dirname = path.split("/").last | |
| [ | |
| "aws s3 sync #{path} s3://#{target_bucket}/#{target_prefix}/#{dirname}", | |
| "aws s3 ls s3://#{target_bucket}" | |
| ].each do |command| | |
| system command | |
| end | |
| end | |
| # upload files | |
| target_file_path.each do |path| | |
| next unless File.exist? path | |
| filename = path.split("/").last | |
| [ | |
| "aws s3 cp #{path} s3://#{target_bucket}/#{target_prefix}/#{filename}", | |
| "aws s3 ls s3://#{target_bucket}" | |
| ].each do |command| | |
| system command | |
| end | |
| end |
This file contains hidden or 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
| git clone [email protected]:FOURIER_INC/fanatic.git | |
| cd fanatic | |
| bundle install | |
| bundle exec app.rb |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment