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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
|
#! /bin/sh
#
# crashdc
#
# Description: The crashdc init script will execute the crashdc command
# on the last vmcore present in /var/crash/{date} directory.
#
# Copyright 2020 Hewlett Packard
#
# chkconfig: - 97 80
#
# Author: Louis Bouchard <louis.bouchard@kamikamamak.fr>
if [[ -f /etc/sysconfig/crashdc ]]; then
. /etc/sysconfig/crashdc
else
echo "The file /etc/sysconfig/crashdc is absent. Cannot run"
exit 1
fi
typeset LOGGER="echo "
mode=$(echo $2 | tr '[:lower:]' '[:upper:]')
if ! [[ -z $mode ]]; then
case "$mode" in
BASIC) CRASHMODE=BASIC
;;
ADVANCED) CRASHMODE=ADVANCED
;;
CUSTOM) CRASHMODE=CUSTOM
if [[ -z $3 ]];then
echo "CUSTOM : Missing crashdc command file"
exit 1
else
CRASHFILE=$3
fi
;;
*) echo "$mode : Invalid crashdc mode"
exit 1
;;
esac
echo -n "Forcing crashdc mode to $CRASHMODE"
if ! [[ -z "$CRASHFILE" ]];then
echo " with $CRASHFILE"
else
echo
fi
fi
find_distro()
{
relfile=$(ls /etc/*release)
rel=$(cat /etc/*release)
set +a $rel
case "$1" in
Red)
rel=rhel
ver=$7
ver=${ver%.*}
echo "${rel}${ver}"
return 0
;;
SUSE)
rel=sles
ver=$5
echo "${rel}${ver}"
return 0
;;
*)
echo "Invalid or inexistant $relfile"
exit 1
;;
esac
}
generate_crashdc()
{
coredir=`ls -rtd ${VMCOREDIR}/*2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]:[0-9][0-9]* | cut -d\ -f2 | tail -1`
kver=$(uname -r)
case $(find_distro) in
rhel[56]) namelist=/usr/lib/debug/lib/modules/${kver}/vmlinux
;;
sles10) namelist=/boot/vmlinux-${kver}
#
# namelist is delivered compressed
# might need to be uncompressed
#
if [ -f ${namelist}.gz ];then
gzip -d -c ${namelist}.gz > $namelist
else
$LOGGER "Unable to locate $namelist. \
Verify that the kernel-debuginfo packages are \
correctly installed or uncompressed."
exit 1
fi
;;
sles11)
namelist=$coredir/vmlinux-$(uname -r)
if [ -f ${namelist}.gz ];then
gzip -d -c ${namelist}.gz > $namelist
else
$LOGGER "Unable to locate $namelist. \
Verify that the kernel-debuginfo packages are \
correctly installed or uncompressed."
exit 1
fi
debuginfo=/usr/lib/debug/boot/vmlinux-$(uname -r).debug
;;
*) echo "Unknown distro"
;;
esac
if ! [[ -r $namelist ]];then
$LOGGER "Unable to locate $namelist. Verify that the kernel-debuginfo packages are correctly installed."
exit 1
fi
case $CRASHMODE in
BASIC ) CRASHMODE="-b";;
ADVANCED ) CRASHMODE="-a";;
CUSTOM ) CRASHMODE="-c $CRASHFILE";;
* ) echo "Invalid CRASHMODE value in /etc/sysconfig/crashdc : $CRASHMODE"
exit 1;;
esac
if [[ -z $debuginfo ]];then
$CRASHDC $CRASHDCDEBUG $CRASHMODE $namelist $coredir/vmcore $coredir
else
$CRASHDC $CRASHDCDEBUG $CRASHMODE $namelist $coredir/vmcore $coredir $debuginfo
fi
CRASHDCSUCCESS=$?
if [[ $CRASHDCSUCCESS == 0 ]];then
return 0
else
return 1
fi
}
check_status()
{
ls -rtd ${VMCOREDIR}/*2[0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]-[0-9][0-9]:[0-9][0-9]* | while read Line;do
crashdata=$(ls ${Line}/crash-data*txt 2> /dev/null)
echo -n $Line :
if [[ -z $crashdata ]];then
echo "crash-data file missing"
else
echo "crash-data file exists"
fi
done
}
case "$1" in
start)
last_crash_data=$(check_status | tail -1)
set -a $last_crash_data
if [[ $4 == "missing" ]];then
generate_crashdc
fi
;;
generate|gen)
generate_crashdc
;;
status)
check_status
;;
*)
echo "Usage: $0 {start|generate|gen} [MODE]"
exit 1
;;
esac
exit $?
|