~louis/crashdc/trunk

76 by louis_bouchard
Initial version of init script to generate crash-data.txt
1
#! /bin/sh
2
3
#
4
#  crashdc
5
#
6
#  Description:  The crashdc init script will execute the crashdc command
7
#  		 on the last vmcore present in /var/crash/{date} directory.
8
#
9
#  Copyright 2020 Hewlett Packard
10
#
87 by louis_bouchard
changed chkconfig start level
11
#  chkconfig: - 97 80
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
12
#
113 by louis_bouchard
Changed email address to avoid spam
13
#  Author:  Louis Bouchard <louis.bouchard@kamikamamak.fr>
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
14
15
81 by louis_bouchard
Implemented custom cmdfile functionality
16
if [[ -f /etc/sysconfig/crashdc ]]; then
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
17
	. /etc/sysconfig/crashdc
96 by louis_bouchard
added error on inexistant sysconfig
18
else
19
        echo "The file /etc/sysconfig/crashdc is absent. Cannot run"
20
        exit 1
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
21
fi
22
81 by louis_bouchard
Implemented custom cmdfile functionality
23
typeset LOGGER="echo "
24
77 by louis_bouchard
mosty working except for CUSTOM mode
25
mode=$(echo $2 | tr '[:lower:]' '[:upper:]')
26
81 by louis_bouchard
Implemented custom cmdfile functionality
27
if ! [[ -z $mode ]]; then
77 by louis_bouchard
mosty working except for CUSTOM mode
28
	case "$mode" in
29
		BASIC) CRASHMODE=BASIC
30
			;;
31
		ADVANCED) CRASHMODE=ADVANCED
32
			;;
33
		CUSTOM) CRASHMODE=CUSTOM
81 by louis_bouchard
Implemented custom cmdfile functionality
34
			if [[ -z $3 ]];then
77 by louis_bouchard
mosty working except for CUSTOM mode
35
				echo "CUSTOM : Missing crashdc command file"
36
				exit 1
37
			else
38
				CRASHFILE=$3
39
			fi
40
			;;
41
		*) echo "$mode : Invalid crashdc mode"
42
			exit 1
43
			;;
44
	esac
81 by louis_bouchard
Implemented custom cmdfile functionality
45
	echo -n "Forcing crashdc mode to $CRASHMODE"
46
	if ! [[ -z "$CRASHFILE" ]];then
47
		echo " with $CRASHFILE"
48
	else
49
		echo
50
	fi
77 by louis_bouchard
mosty working except for CUSTOM mode
51
fi
52
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
53
find_distro()
54
{
55
relfile=$(ls /etc/*release)
56
rel=$(cat /etc/*release)
57
set +a $rel
58
case "$1" in
59
	Red)
60
		rel=rhel
61
		ver=$7
62
		ver=${ver%.*}
63
		echo "${rel}${ver}"
64
		return 0
65
		;;
66
	SUSE)
67
		rel=sles
68
		ver=$5
69
		echo "${rel}${ver}"
70
		return 0
71
		;;
72
	*)
73
		echo "Invalid or inexistant $relfile"
74
		exit 1
75
		;;
76
esac
77
}
78
81 by louis_bouchard
Implemented custom cmdfile functionality
79
generate_crashdc()
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
80
{
134 by louis_bouchard
Bugfix for 3013715, ongoing RHEL6 dev
81
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`
77 by louis_bouchard
mosty working except for CUSTOM mode
82
83
	kver=$(uname -r)
84
	case $(find_distro) in
134 by louis_bouchard
Bugfix for 3013715, ongoing RHEL6 dev
85
		rhel[56]) namelist=/usr/lib/debug/lib/modules/${kver}/vmlinux
77 by louis_bouchard
mosty working except for CUSTOM mode
86
			;;
87
		sles10) namelist=/boot/vmlinux-${kver}
97 by louis_bouchard
test scripts for SLES10
88
			#
89
			# namelist is delivered compressed 
90
			# might need to be uncompressed
91
			#
92
			if [ -f ${namelist}.gz ];then
93
				gzip -d -c ${namelist}.gz > $namelist
94
			else
95
                        	$LOGGER "Unable to locate $namelist. \
104 by louis_bouchard
added sles11 support
96
				Verify that the kernel-debuginfo packages are \
97
				correctly installed or uncompressed."
97 by louis_bouchard
test scripts for SLES10
98
                        	exit 1
99
                	fi
77 by louis_bouchard
mosty working except for CUSTOM mode
100
			;;
101
		sles11)
102
        		namelist=$coredir/vmlinux-$(uname -r)
104 by louis_bouchard
added sles11 support
103
			if [ -f ${namelist}.gz ];then
104
				gzip -d -c ${namelist}.gz > $namelist
105
			else
106
                        	$LOGGER "Unable to locate $namelist. \
107
				Verify that the kernel-debuginfo packages are \
108
				correctly installed or uncompressed."
109
                        	exit 1
110
                	fi
111
        		debuginfo=/usr/lib/debug/boot/vmlinux-$(uname -r).debug
77 by louis_bouchard
mosty working except for CUSTOM mode
112
			;;
113
		*) echo "Unknown distro"
114
			;;
115
	esac
116
81 by louis_bouchard
Implemented custom cmdfile functionality
117
if ! [[ -r $namelist ]];then
77 by louis_bouchard
mosty working except for CUSTOM mode
118
	$LOGGER "Unable to locate $namelist. Verify that the kernel-debuginfo packages are correctly installed."
119
	exit 1
120
fi
121
122
case $CRASHMODE in
123
	BASIC ) CRASHMODE="-b";;
124
	ADVANCED ) CRASHMODE="-a";;
81 by louis_bouchard
Implemented custom cmdfile functionality
125
	CUSTOM ) CRASHMODE="-c $CRASHFILE";;
77 by louis_bouchard
mosty working except for CUSTOM mode
126
	* ) echo "Invalid CRASHMODE value in /etc/sysconfig/crashdc : $CRASHMODE"
127
	exit 1;;
128
esac
129
104 by louis_bouchard
added sles11 support
130
	if [[ -z $debuginfo ]];then
131
		$CRASHDC $CRASHDCDEBUG $CRASHMODE $namelist $coredir/vmcore $coredir
132
	else
133
		$CRASHDC $CRASHDCDEBUG $CRASHMODE $namelist $coredir/vmcore $coredir $debuginfo
134
	fi
77 by louis_bouchard
mosty working except for CUSTOM mode
135
	CRASHDCSUCCESS=$?
81 by louis_bouchard
Implemented custom cmdfile functionality
136
	if [[ $CRASHDCSUCCESS == 0 ]];then
137
		return 0
77 by louis_bouchard
mosty working except for CUSTOM mode
138
	else
81 by louis_bouchard
Implemented custom cmdfile functionality
139
		return 1
77 by louis_bouchard
mosty working except for CUSTOM mode
140
	fi
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
141
}
142
77 by louis_bouchard
mosty working except for CUSTOM mode
143
check_status()
144
{
88 by louis_bouchard
Fixed to avoid creating crash-data.txt file when already exists
145
134 by louis_bouchard
Bugfix for 3013715, ongoing RHEL6 dev
146
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
81 by louis_bouchard
Implemented custom cmdfile functionality
147
        crashdata=$(ls ${Line}/crash-data*txt 2> /dev/null)
148
        echo -n $Line :
149
        if [[ -z $crashdata ]];then
150
                echo "crash-data file missing"
151
        else
152
                echo "crash-data file exists"
153
        fi
154
        done
77 by louis_bouchard
mosty working except for CUSTOM mode
155
}
156
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
157
case "$1" in
88 by louis_bouchard
Fixed to avoid creating crash-data.txt file when already exists
158
  start)
159
	last_crash_data=$(check_status | tail -1)
160
	set -a $last_crash_data
161
	if [[ $4 == "missing" ]];then
162
		generate_crashdc
163
	fi
164
	;;
165
  generate|gen)
81 by louis_bouchard
Implemented custom cmdfile functionality
166
	generate_crashdc
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
167
	;;
168
  status)
77 by louis_bouchard
mosty working except for CUSTOM mode
169
	check_status
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
170
	;;
171
  *)
77 by louis_bouchard
mosty working except for CUSTOM mode
172
	echo "Usage: $0 {start|generate|gen} [MODE]"
76 by louis_bouchard
Initial version of init script to generate crash-data.txt
173
	exit 1
174
	;;
175
esac
176
177
exit $?