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 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 "core" "/var/lib/systemd/coredump" 38) 39 40dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" 41dest="/tmp" 42disable_dreport=false 43 44while [[ $# -gt 0 ]]; do 45 key="$1" 46 case $key in 47 -d|--dir) 48 mkdir -p "$2" 49 if [ $? -eq 0 ]; then 50 dest="$2" 51 else 52 echo "Failed to create the destination directory specified." 53 break 54 fi 55 shift 2 56 ;; 57 -D|--disable_dreport) 58 disable_dreport=true 59 shift 60 ;; 61 -h|--help) 62 echo "$help" 63 exit 64 ;; 65 *) 66 echo "Unknown option $1. Display available options with -h or --help" 67 exit 68 ;; 69 esac 70done 71 72echo "Using destination directory $dest" 73 74if [ $disable_dreport = false ]; then 75 dreport -d $dest -v 76 exit 77fi 78 79mkdir -p "$dest/$dir" 80 81for ((i=0;i<${#arr[@]};i+=2)); do 82 if [ -d "${arr[i+1]}" ]; then 83 echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..." 84 mkdir "$dest/$dir/${arr[i]}" 85 cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]} 86 else 87 echo "Collecting ${arr[i]}..." 88 ${arr[i+1]} >> "$dest/$dir/${arr[i]}" 89 fi 90done 91 92tar -cf "$dest/$dir.tar" -C $dest $dir 93echo "Contents in $dest/$dir.tar" 94 95rm -r "$dest/$dir" 96