-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInformationCollector.sh
161 lines (126 loc) · 4.64 KB
/
InformationCollector.sh
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/bin/bash
# This script will collect information on a running system and hopefully
# gather something useful for later analysis.
# Copyright (c) 2013 Espen Fjellvær Olsen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
echo "Information collector system"
exec 6>&1
exec 2>/dev/null
tmp=`mktemp -d`
logDate=2 # Days of logs to collect
version=1
# Try to collect relevant information about the OS
function collectSystemInformation {
exec > $tmp/systemInformation
echo "*************************************"
echo "*** Standard system information ***"
echo "*************************************"
uname -a
type lsb_release &> /dev/null && lsb_release -a
cat /etc/*release
cat /etc/*version
uptime
echo "*************************************"
echo "*** Kernel messages ***"
echo "*************************************"
dmesg
echo "*************************************"
echo "*** Hardware information ***"
echo "*************************************"
cat /proc/cpuinfo
echo
free -m
echo "*********************************"
echo "*** Virtual memory statistics ***"
echo "*********************************"
vmstat
echo "***********************************"
echo "*** Top 5 CPU eating process ***"
echo "***********************************"
ps auxf | sort -nr -k 3 | head -5
echo "***********************************"
echo "*** Top 5 memory eating process ***"
echo "***********************************"
ps auxf | sort -nr -k 4 | head -5
echo "*************************************"
echo "*** Open files ***"
echo "*************************************"
lsof -n
}
function collectUsers {
exec > $tmp/userInformation
echo "**************************************"
echo "*** Users logged in ***"
echo "**************************************"
who -H -a
echo "**************************************"
echo "*** Last logged in users ***"
echo "**************************************"
last
}
# Collect information about the network
function collectNetworkInformation {
exec > $tmp/networkInformation
echo "**************************************"
echo "*** Network routing ***"
echo "**************************************"
netstat -nr
echo "**************************************"
echo "*** Interface information ***"
echo "**************************************"
/sbin/ifconfig -a
echo "**************************************"
echo "*** Interface traffic information ***"
echo "**************************************"
netstat -i
echo "**************************************"
echo "*** Resolv.conf ***"
echo "**************************************"
cat /etc/resolv.conf
echo "**************************************"
echo "*** Open network connections ***"
echo "**************************************"
netstat -lapn
}
# Collect information about running processes
function collectProcessInformation {
exec > $tmp/processes
echo "**************************************"
echo "*** Running processes ***"
echo "**************************************"
ps auxwwwf
echo "**************************************"
echo "*** Directory of running processes ***"
echo "**************************************"
ls -l /proc/*/cwd
echo "**************************************"
echo "*** Executable of running processes ***"
echo "**************************************"
ls -l /proc/*/exe
echo "**************************************"
echo "*** Arguments of running processes ***"
echo "**************************************"
grep -a ^ /proc/*/cmdline
}
# Collect logs up to $logDate days old
function collectLogs {
mkdir $tmp/logs
find /var/log -mtime -$logDate -exec cp {} $tmp/logs/ \; # Nested folders will blow up...
}
collectSystemInformation
collectUsers
collectNetworkInformation
collectProcessInformation
collectLogs
tar cfz InformationCollector-$(date +%y%m%d).tgz $tmp
rm -rf $tmp