blob: 5587a336c42d7e63f1159e95a6483b94c1f8bb50 [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"
Eddie Jamesc04e0e02023-06-19 10:47:01 -050033 "BMC_traceevents.txt" "cat /sys/kernel/tracing/trace"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060034
35# Copy all content from these directories into directories in the .tar
36# Format: "Directory name" "Directory to copy"
37 "obmc" "/var/lib/obmc/"
Jayanth Othayoth5cca05a2017-07-13 06:00:47 -050038 "core" "/var/lib/systemd/coredump"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060039)
40
41dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")"
42dest="/tmp"
Jayanth Othayothd8166112017-11-02 22:52:18 -050043disable_dreport=false
Michael Tritz3e3f28b2017-01-18 13:54:42 -060044
45while [[ $# -gt 0 ]]; do
46 key="$1"
47 case $key in
48 -d|--dir)
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050049 mkdir -p "$2"
50 if [ $? -eq 0 ]; then
Michael Tritz3e3f28b2017-01-18 13:54:42 -060051 dest="$2"
52 else
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050053 echo "Failed to create the destination directory specified."
Michael Tritz3e3f28b2017-01-18 13:54:42 -060054 break
55 fi
56 shift 2
57 ;;
Jayanth Othayothd8166112017-11-02 22:52:18 -050058 -D|--disable_dreport)
59 disable_dreport=true
60 shift
61 ;;
Michael Tritz3e3f28b2017-01-18 13:54:42 -060062 -h|--help)
63 echo "$help"
64 exit
65 ;;
66 *)
67 echo "Unknown option $1. Display available options with -h or --help"
68 exit
69 ;;
70 esac
71done
72
73echo "Using destination directory $dest"
74
Jayanth Othayothd8166112017-11-02 22:52:18 -050075if [ $disable_dreport = false ]; then
76 dreport -d $dest -v
77 exit
78fi
79
Jayanth Othayotha19440d2017-06-20 06:53:47 -050080mkdir -p "$dest/$dir"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060081
82for ((i=0;i<${#arr[@]};i+=2)); do
83 if [ -d "${arr[i+1]}" ]; then
84 echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..."
85 mkdir "$dest/$dir/${arr[i]}"
86 cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]}
87 else
88 echo "Collecting ${arr[i]}..."
89 ${arr[i+1]} >> "$dest/$dir/${arr[i]}"
90 fi
91done
92
Jayanth Othayotha19440d2017-06-20 06:53:47 -050093tar -cf "$dest/$dir.tar" -C $dest $dir
Michael Tritz3e3f28b2017-01-18 13:54:42 -060094echo "Contents in $dest/$dir.tar"
95
96rm -r "$dest/$dir"