xref: /openbmc/phosphor-debug-collector/ffdc (revision a19440dc)
1#!/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:
10   -d, --dir <directory>  Specify destination directory. Defaults to /tmp if
11                          invalid or unspecified.
12   -h, --help             Display this help text and exit.
13'
14
15declare -a arr=(
16# Commands to be outputted into individual files
17# Format: "File name" "Command"
18      "Build_info.txt"            "cat /etc/version"
19      "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/"
37)
38
39dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")"
40dest="/tmp"
41
42while [[ $# -gt 0 ]]; do
43  key="$1"
44  case $key in
45    -d|--dir)
46      if [ -d "$2" ]; then
47        dest="$2"
48      else
49        echo "Invalid or no destination directory specified."
50        break
51      fi
52      shift 2
53      ;;
54    -h|--help)
55      echo "$help"
56      exit
57      ;;
58    *)
59      echo "Unknown option $1. Display available options with -h or --help"
60      exit
61      ;;
62  esac
63done
64
65echo "Using destination directory $dest"
66
67mkdir -p "$dest/$dir"
68
69for ((i=0;i<${#arr[@]};i+=2)); do
70  if [ -d "${arr[i+1]}" ]; then
71    echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..."
72    mkdir "$dest/$dir/${arr[i]}"
73    cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]}
74  else
75    echo "Collecting ${arr[i]}..."
76    ${arr[i+1]} >> "$dest/$dir/${arr[i]}"
77  fi
78done
79
80tar -cf "$dest/$dir.tar" -C $dest $dir
81echo "Contents in $dest/$dir.tar"
82
83rm -r "$dest/$dir"
84