blob: de1bbe80e0d62c9978d85eb93e2c1cbcfe2bf416 [file] [log] [blame]
Michael Tritz3e3f28b2017-01-18 13:54:42 -06001#!/bin/sh
2
Jayanth Othayothab741df2017-07-13 05:48:33 -05003# TODO openbmc/openbmc#1622 remove -e option related changes.
4
Michael Tritz3e3f28b2017-01-18 13:54:42 -06005help=$'FFDC File Collection Script
6
7Collects various FFDC files and system parameters and places them in a .tar
8
9usage: ffdc [OPTION]
10
11Options:
12 -d, --dir <directory> Specify destination directory. Defaults to /tmp if
13 invalid or unspecified.
Jayanth Othayothab741df2017-07-13 05:48:33 -050014 -e, --enable_dump Enable BMC Dump specific features.
Michael Tritz3e3f28b2017-01-18 13:54:42 -060015 -h, --help Display this help text and exit.
16'
17
18declare -a arr=(
19# Commands to be outputted into individual files
20# Format: "File name" "Command"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060021 "FW_level.txt" "cat /etc/os-release"
22 "BMC_OS.txt" "uname -a"
23 "BMC_uptime.txt" "uptime"
24 "BMC_disk_usage.txt" "df -hT"
25
26 "systemctl_status.txt" "systemctl status | cat"
27 "failed_services.txt" "systemctl --failed"
28 "host_console.txt" "cat /var/log/obmc-console.log"
29
30 "BMC_proc_list.txt" "top -n 1 -b"
31 "BMC_journalctl.txt" "journalctl --no-pager"
32 "BMC_dmesg.txt" "dmesg"
33 "BMC_procinfo.txt" "cat /proc/cpuinfo"
34 "BMC_meminfo.txt" "cat /proc/meminfo"
35
36# Copy all content from these directories into directories in the .tar
37# Format: "Directory name" "Directory to copy"
38 "obmc" "/var/lib/obmc/"
Jayanth Othayoth5cca05a2017-07-13 06:00:47 -050039 "core" "/var/lib/systemd/coredump"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060040)
41
42dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")"
43dest="/tmp"
Jayanth Othayothab741df2017-07-13 05:48:33 -050044enable_dump=false
Michael Tritz3e3f28b2017-01-18 13:54:42 -060045
46while [[ $# -gt 0 ]]; do
47 key="$1"
48 case $key in
49 -d|--dir)
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050050 mkdir -p "$2"
51 if [ $? -eq 0 ]; then
Michael Tritz3e3f28b2017-01-18 13:54:42 -060052 dest="$2"
53 else
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050054 echo "Failed to create the destination directory specified."
Michael Tritz3e3f28b2017-01-18 13:54:42 -060055 break
56 fi
57 shift 2
58 ;;
Jayanth Othayothab741df2017-07-13 05:48:33 -050059 -e|--enable_dump)
60 enable_dump=true
61 shift
62 ;;
Michael Tritz3e3f28b2017-01-18 13:54:42 -060063 -h|--help)
64 echo "$help"
65 exit
66 ;;
67 *)
68 echo "Unknown option $1. Display available options with -h or --help"
69 exit
70 ;;
71 esac
72done
73
74echo "Using destination directory $dest"
75
Jayanth Othayothab741df2017-07-13 05:48:33 -050076if [ $enable_dump = true ]; then
77 id=$(basename $dest)
78 printf -v f_id "%08d" $id
79 dir=$"obmcdump_"$f_id"_$(date +"%s")"
80fi
81
Jayanth Othayotha19440d2017-06-20 06:53:47 -050082mkdir -p "$dest/$dir"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060083
84for ((i=0;i<${#arr[@]};i+=2)); do
85 if [ -d "${arr[i+1]}" ]; then
86 echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..."
87 mkdir "$dest/$dir/${arr[i]}"
88 cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]}
89 else
90 echo "Collecting ${arr[i]}..."
91 ${arr[i+1]} >> "$dest/$dir/${arr[i]}"
92 fi
93done
94
Jayanth Othayotha19440d2017-06-20 06:53:47 -050095tar -cf "$dest/$dir.tar" -C $dest $dir
Michael Tritz3e3f28b2017-01-18 13:54:42 -060096echo "Contents in $dest/$dir.tar"
97
98rm -r "$dest/$dir"