-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathforce_requests.rb
executable file
·51 lines (45 loc) · 1.26 KB
/
force_requests.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#! /usr/bin/ruby
# using ruby 1.9.3p194@global
require 'net/http'
require 'date'
# request a page
def get_web_page(address, page, user_agent = 'logrotation_tester' )
http = Net::HTTP.new(address, 80)
req = Net::HTTP::Get.new("page", {'User-Agent' => user_agent})
response = http.request(req)
return response.body
end
def touch_log_files()
# get logrotated files
logdir = '/var/log/apache2'
dir = Dir.new logdir
files = []
dir.each do |fn|
files << fn if fn =~ /\A.+\.log\.\d+/
end
now = Date.today
files.each do |f|
md = /log\.\d+/.match f
lognum = (/\d+/.match md.to_s).to_s
#puts "#{f} #{lognum}"
date = (now - lognum.to_i)
command = "sudo touch -d #{date} #{logdir}/#{f}"
#p command
`#{command}`
end
end
def day_log()
many = 20
many.times do |y|
#get_web_page('127.0.0.1', '/index.html', "logrotation_tester-#{y}" )
#get_web_page('127.0.0.1', '/wrong-index.html', "logrotation_tester-#{y}" )
#`sudo cp /var/log/apache2/sample_file.txt /var/log/apache2/my_access.log`
end
touch_log_files()
end
70.times do
day_log()
`sudo cp /var/log/apache2/sample_file.txt /var/log/apache2/my_access.log`
`sudo logrotate -v -f ./logrotate_apache2.txt `
`sudo logrotate -v -f ./logrotate_apache3.txt `
end