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 11invalid or unspecified. 12-D, --disable_dreport Disable dreport based dump collection 13-h, --help Display this help text and exit. 14' 15 16declare -a arr=( 17# Commands to be outputted into individual files 18# Format: "File name" "Command" 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 "BMC_traceevents.txt" "cat /sys/kernel/tracing/trace" 34 35# Copy all content from these directories into directories in the .tar 36# Format: "Directory name" "Directory to copy" 37 "obmc" "/var/lib/obmc/" 38 "core" "/var/lib/systemd/coredump" 39) 40 41dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" 42dest="/tmp" 43disable_dreport=false 44 45while [[ $# -gt 0 ]]; do 46 key="$1" 47 case $key in 48 -d|--dir) 49 mkdir -p "$2" 50 if [ $? -eq 0 ]; then 51 dest="$2" 52 else 53 echo "Failed to create the destination directory specified." 54 break 55 fi 56 shift 2 57 ;; 58 -D|--disable_dreport) 59 disable_dreport=true 60 shift 61 ;; 62 -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 75if [ $disable_dreport = false ]; then 76 dreport -d $dest -v 77 exit 78fi 79 80mkdir -p "$dest/$dir" 81 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 93tar -cf "$dest/$dir.tar" -C $dest $dir 94echo "Contents in $dest/$dir.tar" 95 96rm -r "$dest/$dir" 97