13e3f28b4SMichael Tritz#!/bin/sh 23e3f28b4SMichael Tritz 33e3f28b4SMichael Tritzhelp=$'FFDC File Collection Script 43e3f28b4SMichael Tritz 53e3f28b4SMichael TritzCollects various FFDC files and system parameters and places them in a .tar 63e3f28b4SMichael Tritz 73e3f28b4SMichael Tritzusage: ffdc [OPTION] 83e3f28b4SMichael Tritz 93e3f28b4SMichael TritzOptions: 103e3f28b4SMichael Tritz-d, --dir <directory> Specify destination directory. Defaults to /tmp if 113e3f28b4SMichael Tritzinvalid or unspecified. 12d8166111SJayanth Othayoth-D, --disable_dreport Disable dreport based dump collection 133e3f28b4SMichael Tritz-h, --help Display this help text and exit. 143e3f28b4SMichael Tritz' 153e3f28b4SMichael Tritz 163e3f28b4SMichael Tritzdeclare -a arr=( 173e3f28b4SMichael Tritz# Commands to be outputted into individual files 183e3f28b4SMichael Tritz# Format: "File name" "Command" 193e3f28b4SMichael Tritz "FW_level.txt" "cat /etc/os-release" 203e3f28b4SMichael Tritz "BMC_OS.txt" "uname -a" 213e3f28b4SMichael Tritz "BMC_uptime.txt" "uptime" 223e3f28b4SMichael Tritz "BMC_disk_usage.txt" "df -hT" 233e3f28b4SMichael Tritz 243e3f28b4SMichael Tritz "systemctl_status.txt" "systemctl status | cat" 253e3f28b4SMichael Tritz "failed_services.txt" "systemctl --failed" 263e3f28b4SMichael Tritz "host_console.txt" "cat /var/log/obmc-console.log" 273e3f28b4SMichael Tritz 283e3f28b4SMichael Tritz "BMC_proc_list.txt" "top -n 1 -b" 293e3f28b4SMichael Tritz "BMC_journalctl.txt" "journalctl --no-pager" 303e3f28b4SMichael Tritz "BMC_dmesg.txt" "dmesg" 313e3f28b4SMichael Tritz "BMC_procinfo.txt" "cat /proc/cpuinfo" 323e3f28b4SMichael Tritz "BMC_meminfo.txt" "cat /proc/meminfo" 33*c04e0e0aSEddie James "BMC_traceevents.txt" "cat /sys/kernel/tracing/trace" 343e3f28b4SMichael Tritz 353e3f28b4SMichael Tritz# Copy all content from these directories into directories in the .tar 363e3f28b4SMichael Tritz# Format: "Directory name" "Directory to copy" 373e3f28b4SMichael Tritz "obmc" "/var/lib/obmc/" 385cca05a8SJayanth Othayoth "core" "/var/lib/systemd/coredump" 393e3f28b4SMichael Tritz) 403e3f28b4SMichael Tritz 413e3f28b4SMichael Tritzdir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" 423e3f28b4SMichael Tritzdest="/tmp" 43d8166111SJayanth Othayothdisable_dreport=false 443e3f28b4SMichael Tritz 453e3f28b4SMichael Tritzwhile [[ $# -gt 0 ]]; do 463e3f28b4SMichael Tritz key="$1" 473e3f28b4SMichael Tritz case $key in 483e3f28b4SMichael Tritz -d|--dir) 49599c7afeSJayanth Othayoth mkdir -p "$2" 50599c7afeSJayanth Othayoth if [ $? -eq 0 ]; then 513e3f28b4SMichael Tritz dest="$2" 523e3f28b4SMichael Tritz else 53599c7afeSJayanth Othayoth echo "Failed to create the destination directory specified." 543e3f28b4SMichael Tritz break 553e3f28b4SMichael Tritz fi 563e3f28b4SMichael Tritz shift 2 573e3f28b4SMichael Tritz ;; 58d8166111SJayanth Othayoth -D|--disable_dreport) 59d8166111SJayanth Othayoth disable_dreport=true 60d8166111SJayanth Othayoth shift 61d8166111SJayanth Othayoth ;; 623e3f28b4SMichael Tritz -h|--help) 633e3f28b4SMichael Tritz echo "$help" 643e3f28b4SMichael Tritz exit 653e3f28b4SMichael Tritz ;; 663e3f28b4SMichael Tritz *) 673e3f28b4SMichael Tritz echo "Unknown option $1. Display available options with -h or --help" 683e3f28b4SMichael Tritz exit 693e3f28b4SMichael Tritz ;; 703e3f28b4SMichael Tritz esac 713e3f28b4SMichael Tritzdone 723e3f28b4SMichael Tritz 733e3f28b4SMichael Tritzecho "Using destination directory $dest" 743e3f28b4SMichael Tritz 75d8166111SJayanth Othayothif [ $disable_dreport = false ]; then 76d8166111SJayanth Othayoth dreport -d $dest -v 77d8166111SJayanth Othayoth exit 78d8166111SJayanth Othayothfi 79d8166111SJayanth Othayoth 80a19440dcSJayanth Othayothmkdir -p "$dest/$dir" 813e3f28b4SMichael Tritz 823e3f28b4SMichael Tritzfor ((i=0;i<${#arr[@]};i+=2)); do 833e3f28b4SMichael Tritz if [ -d "${arr[i+1]}" ]; then 843e3f28b4SMichael Tritz echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..." 853e3f28b4SMichael Tritz mkdir "$dest/$dir/${arr[i]}" 863e3f28b4SMichael Tritz cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]} 873e3f28b4SMichael Tritz else 883e3f28b4SMichael Tritz echo "Collecting ${arr[i]}..." 893e3f28b4SMichael Tritz ${arr[i+1]} >> "$dest/$dir/${arr[i]}" 903e3f28b4SMichael Tritz fi 913e3f28b4SMichael Tritzdone 923e3f28b4SMichael Tritz 93a19440dcSJayanth Othayothtar -cf "$dest/$dir.tar" -C $dest $dir 943e3f28b4SMichael Tritzecho "Contents in $dest/$dir.tar" 953e3f28b4SMichael Tritz 963e3f28b4SMichael Tritzrm -r "$dest/$dir" 97