blob: 6c32abc674fd35bde668c1abe37c8ca5dc8e3f49 [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:
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"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060018 "FW_level.txt" "cat /etc/os-release"
19 "BMC_OS.txt" "uname -a"
20 "BMC_uptime.txt" "uptime"
21 "BMC_disk_usage.txt" "df -hT"
22
23 "systemctl_status.txt" "systemctl status | cat"
24 "failed_services.txt" "systemctl --failed"
25 "host_console.txt" "cat /var/log/obmc-console.log"
26
27 "BMC_proc_list.txt" "top -n 1 -b"
28 "BMC_journalctl.txt" "journalctl --no-pager"
29 "BMC_dmesg.txt" "dmesg"
30 "BMC_procinfo.txt" "cat /proc/cpuinfo"
31 "BMC_meminfo.txt" "cat /proc/meminfo"
32
33# Copy all content from these directories into directories in the .tar
34# Format: "Directory name" "Directory to copy"
35 "obmc" "/var/lib/obmc/"
Jayanth Othayoth5cca05a2017-07-13 06:00:47 -050036 "core" "/var/lib/systemd/coredump"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060037)
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)
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050046 mkdir -p "$2"
47 if [ $? -eq 0 ]; then
Michael Tritz3e3f28b2017-01-18 13:54:42 -060048 dest="$2"
49 else
Jayanth Othayoth599c7af2017-07-09 21:18:32 -050050 echo "Failed to create the destination directory specified."
Michael Tritz3e3f28b2017-01-18 13:54:42 -060051 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
Jayanth Othayotha19440d2017-06-20 06:53:47 -050068mkdir -p "$dest/$dir"
Michael Tritz3e3f28b2017-01-18 13:54:42 -060069
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
Jayanth Othayotha19440d2017-06-20 06:53:47 -050081tar -cf "$dest/$dir.tar" -C $dest $dir
Michael Tritz3e3f28b2017-01-18 13:54:42 -060082echo "Contents in $dest/$dir.tar"
83
84rm -r "$dest/$dir"