@@ -44,13 +44,14 @@ def run
44
44
vprint_status ( "Retrieving history for #{ users . length } users" )
45
45
shells = %w{ ash bash csh ksh sh tcsh zsh }
46
46
users . each do |u |
47
+ home = get_home_dir ( u )
47
48
shells . each do |shell |
48
- get_shell_history ( u , shell )
49
+ get_shell_history ( u , home , shell )
49
50
end
50
- get_mysql_history ( u )
51
- get_psql_history ( u )
52
- get_mongodb_history ( u )
53
- get_vim_history ( u )
51
+ get_mysql_history ( u , home )
52
+ get_psql_history ( u , home )
53
+ get_mongodb_history ( u , home )
54
+ get_vim_history ( u , home )
54
55
end
55
56
56
57
last = execute ( '/usr/bin/last && /usr/bin/lastlog' )
@@ -88,54 +89,47 @@ def cat_file(filename)
88
89
output
89
90
end
90
91
91
- def get_shell_history ( user , shell )
92
+ def get_home_dir ( user )
93
+ home = execute ( "echo ~#{ user } " )
94
+ if home . empty?
95
+ if user == 'root'
96
+ return '/root'
97
+ else
98
+ return "/home/#{ user } "
99
+ end
100
+ end
101
+ home
102
+ end
103
+
104
+ def get_shell_history ( user , home , shell )
92
105
return if shell . nil?
93
106
vprint_status ( "Extracting #{ shell } history for #{ user } " )
94
- if user == 'root'
95
- hist = cat_file ( "/root/.#{ shell } _history" )
96
- else
97
- hist = cat_file ( "/home/#{ user } /.#{ shell } _history" )
98
- end
107
+ hist = cat_file ( "#{ home } /.#{ shell } _history" )
99
108
save ( "#{ shell } History for #{ user } " , hist ) unless hist . blank? || hist =~ /No such file or directory/
100
109
end
101
110
102
- def get_mysql_history ( user )
111
+ def get_mysql_history ( user , home )
103
112
vprint_status ( "Extracting MySQL history for #{ user } " )
104
- if user == 'root'
105
- sql_hist = cat_file ( '/root/.mysql_history' )
106
- else
107
- sql_hist = cat_file ( "/home/#{ user } /.mysql_history" )
108
- end
113
+ sql_hist = cat_file ( "#{ home } /.mysql_history" )
109
114
save ( "MySQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
110
115
end
111
116
112
- def get_psql_history ( user )
117
+ def get_psql_history ( user , home )
113
118
vprint_status ( "Extracting PostgreSQL history for #{ user } " )
114
- if user == 'root'
115
- sql_hist = cat_file ( '/root/.psql_history' )
116
- else
117
- sql_hist = cat_file ( "/home/#{ user } /.psql_history" )
118
- end
119
+ sql_hist = cat_file ( "#{ home } /.psql_history" )
119
120
save ( "PostgreSQL History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
120
121
end
121
122
122
- def get_mongodb_history ( user )
123
+ def get_mongodb_history ( user , home )
123
124
vprint_status ( "Extracting MongoDB history for #{ user } " )
124
- if user == 'root'
125
- sql_hist = cat_file ( '/root/.dbshell' )
126
- else
127
- sql_hist = cat_file ( "/home/#{ user } /.dbshell" )
128
- end
125
+ sql_hist = cat_file ( "#{ home } /.dbshell" )
129
126
save ( "MongoDB History for #{ user } " , sql_hist ) unless sql_hist . blank? || sql_hist =~ /No such file or directory/
130
127
end
131
128
132
- def get_vim_history ( user )
129
+ def get_vim_history ( user , home )
133
130
vprint_status ( "Extracting VIM history for #{ user } " )
134
- if user == 'root'
135
- vim_hist = cat_file ( '/root/.viminfo' )
136
- else
137
- vim_hist = cat_file ( "/home/#{ user } /.viminfo" )
138
- end
131
+ vim_hist = cat_file ( "#{ home } /.viminfo" )
139
132
save ( "VIM History for #{ user } " , vim_hist ) unless vim_hist . blank? || vim_hist =~ /No such file or directory/
140
133
end
141
134
end
135
+
0 commit comments