blob: f08649a3df13e7f2ded8a551c1386ad662768524 [file] [log] [blame]
Michael Tritz3e3f28b2017-01-18 13:54:42 -06001#!/bin/sh
2
3help=$'FFDC File Collection Script
4
5Collects various FFDC files and system parameters and places them in a .tar
6
7usage: ffdc [OPTION]
8
9Options:
Patrick Williams9d26e4f2022-12-08 06:46:44 -060010-d, --dir <directory> Specify destination directory. Defaults to /tmp if
11invalid or unspecified.
12-D, --disable_dreport Disable dreport based dump collection
13-h, --help Display this help text and exit.
Michael Tritz3e3f28b2017-01-18 13:54:42 -060014'
15
16declare -a arr=(
17# Commands to be outputted into individual files
18# Format: "File name" "Command"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060019 "FW_level.txt" "cat /etc/os-release"
20 "BMC_OS.txt" "uname -a"
21 "BMC_uptime.txt" "uptime"
22 "BMC_disk_usage.txt" "df -hT"
23
24 "systemctl_status.txt" "systemctl status | cat"
25 "failed_services.txt" "systemctl --failed"
26 "host_console.txt" "cat /var/log/obmc-console.log"
27
28 "BMC_proc_list.txt" "top -n 1 -b"
29 "BMC_journalctl.txt" "journalctl --no-pager"
30 "BMC_dmesg.txt" "dmesg"
31 "BMC_procinfo.txt" "cat /proc/cpuinfo"
32 "BMC_meminfo.txt" "cat /proc/meminfo"
33
34# Copy all content from these directories into directories in the .tar
35# Format: "Directory name" "Directory to copy"
36 "obmc" "/var/lib/obmc/"
Jayanth Othayoth5cca05a2017-07-13 06:00:47 -050037 "core" "/var/lib/systemd/coredump"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060038)
39
40dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")"
41dest="/tmp"
Jayanth Othayothd8166112017-11-02 22:52:18 -050042disable_dreport=false
Michael Tritz3e3f28b2017-01-18 13:54:42 -060043
44while [[ $# -gt 0 ]]; do
45 key="$1"
46 case $key in
47 -d|--dir)
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050048 mkdir -p "$2"
49 if [ $? -eq 0 ]; then
Michael Tritz3e3f28b2017-01-18 13:54:42 -060050 dest="$2"
51 else
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050052 echo "Failed to create the destination directory specified."
Michael Tritz3e3f28b2017-01-18 13:54:42 -060053 break
54 fi
55 shift 2
56 ;;
Jayanth Othayothd8166112017-11-02 22:52:18 -050057 -D|--disable_dreport)
58 disable_dreport=true
59 shift
60 ;;
Michael Tritz3e3f28b2017-01-18 13:54:42 -060061 -h|--help)
62 echo "$help"
63 exit
64 ;;
65 *)
66 echo "Unknown option $1. Display available options with -h or --help"
67 exit
68 ;;
69 esac
70done
71
72echo "Using destination directory $dest"
73
Jayanth Othayothd8166112017-11-02 22:52:18 -050074if [ $disable_dreport = false ]; then
75 dreport -d $dest -v
76 exit
77fi
78
Jayanth Othayotha19440d2017-06-20 06:53:47 -050079mkdir -p "$dest/$dir"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060080
81for ((i=0;i<${#arr[@]};i+=2)); do
82 if [ -d "${arr[i+1]}" ]; then
83 echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..."
84 mkdir "$dest/$dir/${arr[i]}"
85 cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]}
86 else
87 echo "Collecting ${arr[i]}..."
88 ${arr[i+1]} >> "$dest/$dir/${arr[i]}"
89 fi
90done
91
Jayanth Othayotha19440d2017-06-20 06:53:47 -050092tar -cf "$dest/$dir.tar" -C $dest $dir
Michael Tritz3e3f28b2017-01-18 13:54:42 -060093echo "Contents in $dest/$dir.tar"
94
95rm -r "$dest/$dir"