-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patht_capture_logs.rb
executable file
·76 lines (61 loc) · 1.54 KB
/
t_capture_logs.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#! /usr/bin/ruby
=begin
--------------------------------------------------------------------------------
Make a copy of the Tomcat logs in a time-stamped subdirectory of the instance
directory.
--------------------------------------------------------------------------------
=end
$: << File.dirname(File.expand_path(__FILE__))
require 'common'
require 'date'
def figure_time_stamp()
return DateTime.now.strftime("%Y-%m-%d_%H-%M-%S")
end
def logs_dir()
"#{$instance.tomcat.path}/logs"
end
def confirm_logs_exist()
log_files = Dir.entries(logs_dir).delete_if() {|fn| fn.start_with?(".")}
raise UserInputError.new("There are no Tomcat logs") if log_files.empty?
end
def create_dir
tomcat_logs_dir = $instance.file('logs')
Dir.mkdir(tomcat_logs_dir) unless File.directory?(tomcat_logs_dir)
@this_logs_dir = File.expand_path("Tomcat_#{figure_time_stamp}", tomcat_logs_dir)
Dir.mkdir(@this_logs_dir)
end
def copy_logs()
Dir.chdir(@this_logs_dir) do
system("cp #{logs_dir}/* .")
end
end
def add_read_me()
puts "Add a comment for the README.txt file"
comment = STDIN.gets.strip
return if comment.empty?
Dir.chdir(@this_logs_dir) do
File.open('README.txt', "w") do |file|
file.puts comment
end
end
end
#
# ---------------------------------------------------------
# MAIN ROUTINE
# ---------------------------------------------------------
#
begin
$instance.tomcat.confirm
confirm_logs_exist
create_dir
copy_logs
add_read_me
rescue SettingsError
puts
puts $!
puts
rescue UserInputError
puts
puts $!
puts
end