| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 1 | #!/bin/sh | 
|  | 2 |  | 
|  | 3 | help=$'FFDC File Collection Script | 
|  | 4 |  | 
|  | 5 | Collects various FFDC files and system parameters and places them in a .tar | 
|  | 6 |  | 
|  | 7 | usage: ffdc [OPTION] | 
|  | 8 |  | 
|  | 9 | Options: | 
| Patrick Williams | 9d26e4f | 2022-12-08 06:46:44 -0600 | [diff] [blame] | 10 | -d, --dir <directory>  Specify destination directory. Defaults to /tmp if | 
|  | 11 | invalid or unspecified. | 
|  | 12 | -D, --disable_dreport  Disable dreport based dump collection | 
|  | 13 | -h, --help             Display this help text and exit. | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 14 | ' | 
|  | 15 |  | 
|  | 16 | declare -a arr=( | 
|  | 17 | # Commands to be outputted into individual files | 
|  | 18 | # Format: "File name" "Command" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 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" | 
| Jian Zhang | 41167a2 | 2024-12-10 23:14:05 +0800 | [diff] [blame] | 29 | "BMC_journalctl.txt"        "journalctl --namespace=* --no-pager" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 30 | "BMC_dmesg.txt"             "dmesg" | 
|  | 31 | "BMC_procinfo.txt"          "cat /proc/cpuinfo" | 
|  | 32 | "BMC_meminfo.txt"           "cat /proc/meminfo" | 
| Eddie James | c04e0e0 | 2023-06-19 10:47:01 -0500 | [diff] [blame] | 33 | "BMC_traceevents.txt"       "cat /sys/kernel/tracing/trace" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 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/" | 
| Jayanth Othayoth | 5cca05a | 2017-07-13 06:00:47 -0500 | [diff] [blame] | 38 | "core"                      "/var/lib/systemd/coredump" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 39 | ) | 
|  | 40 |  | 
|  | 41 | dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" | 
|  | 42 | dest="/tmp" | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 43 | disable_dreport=false | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 44 |  | 
|  | 45 | while [[ $# -gt 0 ]]; do | 
|  | 46 | key="$1" | 
|  | 47 | case $key in | 
|  | 48 | -d|--dir) | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 49 | mkdir -p "$2" | 
|  | 50 | if [ $? -eq 0 ]; then | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 51 | dest="$2" | 
|  | 52 | else | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 53 | echo "Failed to create the destination directory specified." | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 54 | break | 
|  | 55 | fi | 
|  | 56 | shift 2 | 
|  | 57 | ;; | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 58 | -D|--disable_dreport) | 
|  | 59 | disable_dreport=true | 
|  | 60 | shift | 
|  | 61 | ;; | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 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 | 
|  | 71 | done | 
|  | 72 |  | 
|  | 73 | echo "Using destination directory $dest" | 
|  | 74 |  | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 75 | if [ $disable_dreport = false ]; then | 
|  | 76 | dreport -d $dest -v | 
|  | 77 | exit | 
|  | 78 | fi | 
|  | 79 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 80 | mkdir -p "$dest/$dir" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 81 |  | 
|  | 82 | for ((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 | 
|  | 91 | done | 
|  | 92 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 93 | tar -cf "$dest/$dir.tar" -C $dest $dir | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 94 | echo "Contents in $dest/$dir.tar" | 
|  | 95 |  | 
|  | 96 | rm -r "$dest/$dir" |