blob: d37131c94a171589b54bf390007c09e9b08772b8 [file] [log] [blame]
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -05001#! /bin/bash
2
3help=$"
4 dreport creates an archive(xz compressed) consisting of the following:
5 * Configuration information
6 * Debug information
7 * A summary report
8 The type parameter controls the content of the data. The generated
9 archive is stored in the user specified location.
10
11usage: dreport [OPTION]
12
13Options:
14 -n, —-name <name> Name to be used for the archive.
15 Default name format obmcdump_<id>_<epochtime>
16 -d, —-dir <directory> Archive directory to copy the compressed report.
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050017 Default output directory is /tmp
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -050018 -i, —-id <id> Dump identifier to associate with the archive.
19 Identifiers include numeric characters.
20 Default dump identifier is 0
21 -t, —-type <type> Data collection type. Valid types are
Jayanth Othayothd8916432017-09-03 23:14:47 -050022 "user", "core", "elog".
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -050023 Default type is "user" initiated.
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -050024 -p, —-path <path> Optional contents to be included in the archive.
25 Valid paths are absolute file path or d-bus path
26 based on type parameter.
27 -Absolute file path for "core" type.
Jayanth Othayothd8916432017-09-03 23:14:47 -050028 -elog d-bus object for "elog" type.
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -050029 -s, --size <size> Maximum allowed size(in KB) of the archive.
30 Report will be truncated in case size exceeds
Jayanth Othayothad516f42017-09-03 21:17:27 -050031 this limit. Default size is unlimited.
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -050032 -v, —-verbose Increase logging verbosity.
33 -V, --version Output version information.
34 -q, —-quiet Only log fatal errors to stderr
35 -h, —-help Display this help and exit.
36"
37
Jayanth Othayoth7b774872017-07-26 05:02:53 -050038#CONSTANTS
39declare -r TRUE=1
40declare -r FALSE=0
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050041declare -r UNLIMITED="unlimited"
42declare -r SUMMARY_DUMP="summary"
43declare -r TYPE_USER="user"
44declare -r TYPE_CORE="core"
Jayanth Othayothd8916432017-09-03 23:14:47 -050045declare -r TYPE_ELOG="elog"
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -050046declare -r SUMMARY_LOG="summary.log"
47declare -r DREPORT_LOG="dreport.log"
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050048declare -r TMP_DIR="/tmp"
49declare -r EPOCHTIME=$(date +"%s")
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -050050declare -r TIME_STAMP="date -u"
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050051
52#Error Codes
53declare -r SUCCESS="0"
54declare -r INTERNAL_FAILURE="1"
55declare -r RESOURCE_UNAVAILABLE="2"
Jayanth Othayoth7b774872017-07-26 05:02:53 -050056
57#VARIABLES
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050058declare -x name=""
Jayanth Othayothff0699d2017-07-26 07:53:03 -050059declare -x dump_dir="/tmp"
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050060declare -x dump_id="00000000"
61declare -x dump_type=$TYPE_USER
Jayanth Othayoth7b774872017-07-26 05:02:53 -050062declare -x verbose=$FALSE
63declare -x quiet=$FALSE
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050064declare -x dump_size="unlimited"
65declare -x name_dir=""
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -050066declare -x optional_path=""
Jayanth Othayoth230e9a32017-08-09 06:39:59 -050067declare -x dreport_log=""
68declare -x summary_log=""
Jayanth Othayothc2ece2d2017-08-09 06:57:12 -050069declare -x cur_dump_size=0
Jayanth Othayoth0862c482017-08-09 07:02:36 -050070declare -a command_list=("")
Jayanth Othayothfa388d02017-09-03 22:34:14 -050071declare -x pid="0"
Jayanth Othayothd8916432017-09-03 23:14:47 -050072declare -x elog_id=""
73
74# @brief Initialize general command array
75# Set of commands, which provide general debug information
76function runlevel_general()
77{
78command_list=(
79 get_fw_level
80 bmc_state
81 host_state
82 chassis_state
83 get_host_info
84 get_uname
85 get_uptime
86 get_disk_usage
87 get_host_info
88 get_cpuinfo
89 get_meminfo
90 get_top
91 )
92}
Jayanth Othayoth0862c482017-08-09 07:02:36 -050093
94# @brief Initialize user type command array
95function runlevel_user()
96{
97command_list=(
Jayanth Othayoth0862c482017-08-09 07:02:36 -050098 get_journal
Jayanth Othayothd8916432017-09-03 23:14:47 -050099 get_elog_all
100 get_obmc_console
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500101 get_failed_services
102 )
103}
104
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500105# @brief Initialize core type command array
106function runlevel_core()
107{
108command_list=(
109 move_optional_file
110 get_proc_journal
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500111 get_failed_services
112 get_obmc_console
Jayanth Othayothd8916432017-09-03 23:14:47 -0500113 )
114}
115
116# @brief Initialize elog type command array
117function runlevel_elog()
118{
119command_list=(
120 get_proc_journal
121 get_elog
122 )
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500123}
124
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500125function get_fw_level()
126{
127 desc="Firmware Release"
128 command="cat /etc/os-release"
129 copy_loc="firmware_release.log"
130 run_command "$command" "$copy_loc" "$desc"
131}
132
133function get_uname()
134{
135 desc="uname"
136 command="uname -a"
137 copy_loc="uname.log"
138 run_command "$command" "$copy_loc" "$desc"
139}
140
141function get_uptime()
142{
143 desc="uptime"
144 command="uptime"
145 copy_loc="uptime.log"
146 run_command "$command" "$copy_loc" "$desc"
147}
148
149function get_disk_usage()
150{
151 desc="Disk Usage"
152 command="df -hT"
153 copy_loc="disk_usage.log"
154 run_command "$command" "$copy_loc" "$desc"
155}
156
157function get_journal()
158{
159 desc="Journal log"
160 command="journalctl -o json-pretty -r"
161 copy_loc="journal.log"
162 run_command "$command" "$copy_loc" "$desc"
163}
164
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500165function get_proc_journal()
166{
167 desc="Process Journal log"
Jayanth Othayothfa388d02017-09-03 22:34:14 -0500168 command="journalctl -o verbose _PID=$pid"
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500169 copy_loc="proc_journal.log"
170 run_command "$command" "$copy_loc" "$desc"
171}
172
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500173function get_host_info()
174{
175 desc="Host information"
176 command="hostnamectl status"
177 copy_loc="hostnamectl.log"
178 run_command "$command" "$copy_loc" "$desc"
179}
180
181function get_failed_services()
182{
183 desc="Failed Services"
184 command="systemctl --failed"
185 copy_loc="failed_services.log"
186 run_command "$command" "$copy_loc" "$desc"
187}
188
189function get_obmc_console()
190{
191 desc="OBMC Console"
192 command="cat /var/log/obmc-console.log"
193 copy_loc="obmc_console.log"
194 run_command "$command" "$copy_loc" "$desc"
195}
196
197function get_cpuinfo()
198{
199 desc="cpuinfo"
200 command="cat /proc/cpuinfo"
201 copy_loc="cpuinfo.log"
202 run_command "$command" "$copy_loc" "$desc"
203}
204
205function get_meminfo()
206{
207 desc="meminfo"
208 command="cat /proc/meminfo"
209 copy_loc="meminfo.log"
210 run_command "$command" "$copy_loc" "$desc"
211}
212
213function get_top()
214{
215 desc="top"
216 command="top -n 1 -b"
217 copy_loc="top.log"
218 run_command "$command" "$copy_loc" "$desc"
219}
220
221function bmc_state()
222{
223 desc="BMC State"
224 command="busctl get-property \
225 xyz.openbmc_project.State.BMC \
226 /xyz/openbmc_project/state/bmc0 \
227 xyz.openbmc_project.State.BMC \
228 CurrentBMCState"
229 copy_loc="BMCState.log"
230 run_command "$command" "$copy_loc" "$desc"
231}
232
233function host_state()
234{
235 desc="Host State"
236 command="busctl get-property \
237 xyz.openbmc_project.State.Host \
238 /xyz/openbmc_project/state/host0 \
239 xyz.openbmc_project.State.Host \
240 CurrentHostState"
241 copy_loc="HostState.log"
242 run_command "$command" "$copy_loc" "$desc"
243}
244
245function chassis_state()
246{
247 desc="Chassis State"
248 command="busctl get-property \
249 xyz.openbmc_project.State.Chassis \
250 /xyz/openbmc_project/state/chassis0 \
251 xyz.openbmc_project.State.Chassis \
252 CurrentPowerState"
Jayanth Othayoth6cd3ca12017-09-01 01:21:28 -0500253 copy_loc="ChassisState.log"
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500254 run_command "$command" "$copy_loc" "$desc"
255}
256
Jayanth Othayothd8916432017-09-03 23:14:47 -0500257# @brief get all available elogs in BMC.
Jayanth Othayoth65a409f2017-09-03 21:26:27 -0500258function get_elog_all()
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500259{
Jayanth Othayoth65a409f2017-09-03 21:26:27 -0500260 desc="elog"
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500261
262 entries=$(busctl --list --no-pager tree \
263 xyz.openbmc_project.Logging | grep \
264 '/xyz/openbmc_project/logging/entry/')
265
266 #check for eSEL entries.
267 if [ -z "$entries" ]; then
268 log_info "No $desc entries"
269 return 0
270 fi
271
272 command="busctl --list --no-pager tree \
273 xyz.openbmc_project.Logging | grep \
274 '/xyz/openbmc_project/logging/entry/' \
275 | xargs -I {} busctl --verbose --no-pager \
276 call xyz.openbmc_project.Logging {} \
277 org.freedesktop.DBus.Properties GetAll s \
278 xyz.openbmc_project.Logging.Entry"
Jayanth Othayoth65a409f2017-09-03 21:26:27 -0500279 copy_loc="elog.log"
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500280 run_command "$command" "$copy_loc" "$desc"
281}
282
Jayanth Othayothd8916432017-09-03 23:14:47 -0500283# @brief get elog specific to global elog_id
284function get_elog()
285{
286 desc="elog id:$elog_id"
287
288 command="busctl --verbose --no-pager \
289 call xyz.openbmc_project.Logging \
290 $optional_path \
291 org.freedesktop.DBus.Properties GetAll s \
292 xyz.openbmc_project.Logging.Entry"
293 copy_loc="elog_$elog_id.log"
294 run_command "$command" "$copy_loc" "$desc"
295}
296
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500297function move_optional_file()
298{
299 desc="Move Optional file"
300
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500301 mv $optional_path $name_dir
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500302 if [ $? -ne 0 ]; then
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500303 log_error "Failed to move file $optional_path"
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500304 return 1
305 fi
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500306 if check_size "$name_dir/$(basename "$optional_path")"; then
Jayanth Othayothe61aee32017-08-09 07:05:06 -0500307 log_info "Moving file $file_name"
308 else
309 log_warning "Skipping $file_name move"
310 fi
311}
312
Jayanth Othayoth0862c482017-08-09 07:02:36 -0500313# @brief Run the requested command and save the output
314# into temporary location for successful size check
315
316function run_command()
317{
318 command="$1"
319 copy_loc="$2"
320 desc="$3"
321
322 eval $command >> "$name_dir/$copy_loc"
323 if [ $? -ne 0 ]; then
324 log_error "Failed to collect $desc"
325 return 1
326 fi
327
328 if check_size "$name_dir/$copy_loc"; then
329 log_info "Collected $desc"
330 else
331 log_warning "Skipping $desc"
332 fi
333}
Jayanth Othayothc2ece2d2017-08-09 06:57:12 -0500334
Jayanth Othayothacf46e32017-08-09 07:15:18 -0500335# @brief Initiate data collection based on the type.
336# @return 0 on success, error code otherwise
337function collect_data()
338{
Jayanth Othayothd8916432017-09-03 23:14:47 -0500339 runlevel_general
340 capture_data "${command_list[@]}"
341
Jayanth Othayothacf46e32017-08-09 07:15:18 -0500342 case $dump_type in
343 $TYPE_USER)
344 runlevel_user
345 capture_data "${command_list[@]}"
346 ;;
347 $TYPE_CORE)
Jayanth Othayothfa388d02017-09-03 22:34:14 -0500348 set_core_pid
Jayanth Othayothacf46e32017-08-09 07:15:18 -0500349 runlevel_core
350 capture_data "${command_list[@]}"
351 ;;
Jayanth Othayothd8916432017-09-03 23:14:47 -0500352 $TYPE_ELOG)
353 elog_id=$(basename "$optional_path")
354 set_elog_pid
355 runlevel_elog
356 capture_data "${command_list[@]}"
357 ;;
358
Jayanth Othayothacf46e32017-08-09 07:15:18 -0500359 $SUMMARY_DUMP)
360 #No data collection is required.
361 ;;
362 *) # unknown option
363 log_error "Skipping: Unknown dump type: $dump_type"
364 ;;
365 esac
366}
367
Jayanth Othayothfa388d02017-09-03 22:34:14 -0500368# @brief set pid by reading information from the optional path.
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500369# dreport "core" type user provides core file as optional path parameter.
Jayanth Othayoth47a14162017-08-09 07:10:39 -0500370# As per coredump source code systemd-coredump uses below format
371# https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
372# /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “.
373# <process ID>.%s000000"
Jayanth Othayothfa388d02017-09-03 22:34:14 -0500374function set_core_pid()
Jayanth Othayoth47a14162017-08-09 07:10:39 -0500375{
Jayanth Othayoth47a14162017-08-09 07:10:39 -0500376 #Escape bash characters in file name
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500377 file=$(printf %q "$optional_path")
Jayanth Othayoth47a14162017-08-09 07:10:39 -0500378
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -0500379 #matching systemd-coredump core file format.
Jayanth Othayothfa388d02017-09-03 22:34:14 -0500380 pid=$(echo $file | awk -F . '{ print $5}')
Jayanth Othayoth47a14162017-08-09 07:10:39 -0500381}
382
Jayanth Othayothd8916432017-09-03 23:14:47 -0500383# @brief set elog pid by reading _PID information from the elog d-bus object.
384# _PID information is stored elog Additional data field
385# Data format "_PID=<pid>"
386function set_elog_pid()
387{
388 additional_data=$(busctl get-property xyz.openbmc_project.Logging \
389 $optional_path \
390 xyz.openbmc_project.Logging.Entry \
391 AdditionalData)
392
393 #read _PID data.
394 if [ ! -z "$additional_data" ]; then
395 pid=$(echo $additional_data | \
396 awk -F _PID= '{ print ($2+0)}')
397 fi
398}
399
Jayanth Othayothf1e02d32017-08-09 07:06:45 -0500400# @brief Capture debug data based on the input command array.
401# and stores in to global temporary name specific location.
402# @param $1 Source array
403# @return 0 on success, error code otherwise
404function capture_data()
405{
406 source=("$@")
407
408 for ((i=0;i<${#source[@]};i+=1)); do
409 ${source[i]}
410 done
411
412 return 0
413}
414
Jayanth Othayothc2ece2d2017-08-09 06:57:12 -0500415# @brief Calculate file or directory compressed size based on input
416# and check whether the size in the the allowed size limit.
417# Remove the file or directory from the name_dir
418# if the check fails.
419# @param $1 Source file or directory
420# @return 0 on success, error code if size exceeds the limit.
421# Limitation: compress and tar will have few bytes size difference
Jayanth Othayothc2ece2d2017-08-09 06:57:12 -0500422function check_size()
423{
424 source=$1
425
426 #No size check required incase dump_size is set to unlimited
427 if [ $dump_size = $UNLIMITED ]; then
428 return 0
429 fi
430
431 #get the file or directory size
432 if [[ -d $source ]] && [[ -n $source ]]; then
433 tar -cf "$source.tar" -C \
434 $(dirname "$source") $(basename "$source")
435 size=$(stat -c%s "$source.tar")
436 rm "$source.tar"
437 else
438 size=$(stat -c%s "$source")
439 fi
440
441 if [ $((size + cur_dump_size)) -gt $dump_size ]; then
442 #Exceed the allowed limit,
443 #tar and compress the files and check the size
444 tar -Jcf "$name_dir.tar.xz" -C \
445 $(dirname "$name_dir") $(basename "$name_dir")
446 size=$(stat -c%s "$name_dir.tar.xz")
447 if [ $size -gt $dump_size ]; then
448 #Remove the the specific data from the name_dir and contniue
449 rm "$source" "$name_dir.tar.xz"
450 return $RESOURCE_UNAVAILABLE
451 else
452 rm "$name_dir.tar.xz"
453 fi
454 fi
455
456 #Remove the compressed file from the name directory
457 cur_dump_size=$((size + cur_dump_size))
458 return $SUCCESS
459}
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500460
Jayanth Othayothe20d5e02017-08-09 06:48:45 -0500461# @brief Initial version of the summary log
462init_summary()
463{
464 log_summary "Name: $name.tar.xz"
465 log_summary "Epochtime: $EPOCHTIME"
466 log_summary "ID: $dump_id"
467 log_summary "Type: $dump_type"
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500468 log_summary "Optional path: $optional_path"
Jayanth Othayothe20d5e02017-08-09 06:48:45 -0500469}
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500470
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500471# @brief Check the validity of user inputs and initialize global
472# variables. Create directory for temporary data collection
473# @return 0 on success, error code otherwise
474
475function initialize()
476{
477 #Dump file name
478 if [ -z $name ]; then
479 name=$"obmcdump_"$dump_id"_$EPOCHTIME"
480 fi
481
482 #Create temporary data directory.
483 mkdir -p "$TMP_DIR/$name"
484 if [ $? -ne 0 ]; then
485 echo "Error: Failed to create the temporary directory."
486 return $RESOURCE_UNAVAILABLE;
487 fi
488
489 #name directory
490 name_dir="$TMP_DIR/$name"
491
492 #dreport log file
493 dreport_log="$name_dir/$DREPORT_LOG"
494
495 #summary log file
496 summary_log="$name_dir/$SUMMARY_LOG"
497
498 #Type
Jayanth Othayothd8916432017-09-03 23:14:47 -0500499 if [[ !($dump_type = $TYPE_USER || \
500 $dump_type = $TYPE_CORE || \
501 $dump_type = $TYPE_ELOG) ]]; then
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500502 log_error "Invalid -type, Only summary log is available"
503 dump_type=$SUMMARY_DUMP
504 fi
505
506 #Size
507 #Check the input is integer.
508 if [ "$dump_size" -eq "$dump_size" ] 2>/dev/null; then
509 #Converts in to bytes.
510 dump_size="$((dump_size * 1024))"
511 else
512 dump_size=$UNLIMITED
513 fi
514
515 return $SUCCESS
516}
517
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500518# @brief Packaging the dump and transferring to dump location.
519function package()
520{
521 mkdir -p "$dump_dir"
522 if [ $? -ne 0 ]; then
523 log_error "Could not create the destination directory $dump_dir"
524 dest_dir=$TMP_DIR
525 fi
526
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500527 #tar and compress the files.
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500528 tar -Jcf "$name_dir.tar.xz" -C \
529 $(dirname "$name_dir") $(basename "$name_dir")
530
531 if [ $? -ne 0 ]; then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500532 echo $($TIME_STAMP) "Could not create the compressed tar file"
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500533 rm -r "$name_dir"
534 return $INTERNAL_FAILURE
535 fi
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500536
537 #remove the temporary name specific directory
538 rm -r "$name_dir"
539
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500540 echo $($TIME_STAMP) "Report is available in $dump_dir"
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500541
542 if [ "$TMP_DIR" == "$dump_dir" ]; then
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500543 return $SUCCESS
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500544 fi
545
546 #copy the compressed tar file into the destination
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500547 cp "$name_dir.tar.xz" "$dump_dir"
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500548 if [ $? -ne 0 ]; then
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500549 echo "Failed to copy the $name_dir.tar.xz to $dump_dir"
550 rm "$name_dir.tar.xz"
551 return $INTERNAL_FAILURE
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500552 fi
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500553
554 #Remove the temporary copy of the file
555 rm "$name_dir.tar.xz"
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500556}
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500557
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500558# @brief log the error message
559# @param error message
560function log_error()
561{
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500562 echo $($TIME_STAMP) "ERROR: $@" >> $dreport_log
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500563 if ((quiet != TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500564 echo $($TIME_STAMP) "ERROR: $@" >&2
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500565 fi
566}
567
568# @brief log warning message
569# @param warning message
570function log_warning()
571{
572 if ((verbose == TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500573 echo $($TIME_STAMP) "WARNING: $@" >> $dreport_log
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500574 if ((quiet != TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500575 echo $($TIME_STAMP) "WARNING: $@" >&2
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500576 fi
577 fi
578}
579
580# @brief log info message
581# @param info message
582function log_info()
583{
584 if ((verbose == TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500585 echo $($TIME_STAMP) "INFO: $@" >> $dreport_log
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500586 if ((quiet != TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500587 echo $($TIME_STAMP) "INFO: $@" >&1
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500588 fi
589 fi
590}
591
592# @brief log summary message
593# @param message
594function log_summary()
595{
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500596 echo $($TIME_STAMP) "$@" >> $summary_log
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500597 if ((quiet != TRUE)); then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500598 echo $($TIME_STAMP) "$@" >&1
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500599 fi
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500600}
601
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500602# @brief Main function
603function main()
604{
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500605 #initialize the global variables and
606 #create temporary storage locations
607 initialize
608 result=$?
609 if [[ ${result} -ne $SUCCESS ]]; then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500610 echo $($TIME_STAMP) "Error: Failed to initialize, Exiting"
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500611 exit;
612 fi
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500613
Jayanth Othayothe20d5e02017-08-09 06:48:45 -0500614 #Initilize the summary log
615 init_summary
616
Jayanth Othayothacf46e32017-08-09 07:15:18 -0500617 #collect data based on the type.
618 collect_data
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500619
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500620 package #package the dump
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500621 result=$?
622 if [[ ${result} -ne $SUCCESS ]]; then
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500623 echo $($TIME_STAMP) "Error: Failed to package, Exiting"
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500624 else
Jayanth Othayothea4b5e52017-08-09 07:31:24 -0500625 echo $($TIME_STAMP) "Sucessfully completed"
Jayanth Othayoth8d0446e2017-08-09 07:26:45 -0500626 exit;
627 fi
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500628}
629
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500630TEMP=`getopt -o n:d:i:t:s:p:vVqh \
631 --long name:,dir:,dumpid:,type:,size:,path:,verbose,version,quiet,help \
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500632 -- "$@"`
Jayanth Othayoth230e9a32017-08-09 06:39:59 -0500633
634if [ $? -ne 0 ]
635then
636 echo "Error: Invalid options"
637 exit 1
638fi
639
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500640eval set -- "$TEMP"
641
642while [[ $# -gt 1 ]]; do
643 key="$1"
644 case $key in
645 -n|--name)
646 name=$2
647 shift 2;;
648 -d|--dir)
Jayanth Othayothff0699d2017-07-26 07:53:03 -0500649 dump_dir=$2
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500650 shift 2;;
651 -i|--dumpid)
652 dump_id=$2
653 shift 2;;
654 -t|--type)
655 dump_type=$2
656 shift 2;;
657 -s|--size)
658 dump_size=$2
659 shift 2;;
Jayanth Othayoth2b05adc2017-09-03 22:15:01 -0500660 -p|--path)
661 optional_path=$2
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500662 shift 2;;
663 -v|—-verbose)
664 verbose=$TRUE
665 shift;;
666 -V|--version)
667 shift;;
668 -q|—-quiet)
669 quiet=$TRUE
670 shift;;
671 -h|--help)
672 echo "$help"
673 exit;;
674 *) # unknown option
Jayanth Othayoth6d3ee1c2017-07-26 05:18:31 -0500675 log_error "Unknown argument: $1"
676 log_info "$help"
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500677 exit 1;;
678 esac
Jayanth Othayoth9e95f4b2017-07-24 06:42:24 -0500679done
Jayanth Othayoth7b774872017-07-26 05:02:53 -0500680
681main #main program
682exit $?