xref: /openbmc/phosphor-debug-collector/ffdc (revision 599c7afe)
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      mkdir -p "$2"
47      if [ $? -eq 0 ]; then
48        dest="$2"
49      else
50        echo "Failed to create the destination directory specified."
51        break
52      fi
53      shift 2
54      ;;
55    -h|--help)
56      echo "$help"
57      exit
58      ;;
59    *)
60      echo "Unknown option $1. Display available options with -h or --help"
61      exit
62      ;;
63  esac
64done
65
66echo "Using destination directory $dest"
67
68mkdir -p "$dest/$dir"
69
70for ((i=0;i<${#arr[@]};i+=2)); do
71  if [ -d "${arr[i+1]}" ]; then
72    echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..."
73    mkdir "$dest/$dir/${arr[i]}"
74    cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]}
75  else
76    echo "Collecting ${arr[i]}..."
77    ${arr[i+1]} >> "$dest/$dir/${arr[i]}"
78  fi
79done
80
81tar -cf "$dest/$dir.tar" -C $dest $dir
82echo "Contents in $dest/$dir.tar"
83
84rm -r "$dest/$dir"
85