| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 1 | #!/bin/sh | 
|  | 2 |  | 
| Jayanth Othayoth | ab741df | 2017-07-13 05:48:33 -0500 | [diff] [blame] | 3 | # TODO openbmc/openbmc#1622 remove -e option related changes. | 
|  | 4 |  | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 5 | help=$'FFDC File Collection Script | 
|  | 6 |  | 
|  | 7 | Collects various FFDC files and system parameters and places them in a .tar | 
|  | 8 |  | 
|  | 9 | usage: ffdc [OPTION] | 
|  | 10 |  | 
|  | 11 | Options: | 
|  | 12 | -d, --dir <directory>  Specify destination directory. Defaults to /tmp if | 
|  | 13 | invalid or unspecified. | 
| Jayanth Othayoth | ab741df | 2017-07-13 05:48:33 -0500 | [diff] [blame] | 14 | -e, --enable_dump      Enable BMC Dump specific features. | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 15 | -h, --help             Display this help text and exit. | 
|  | 16 | ' | 
|  | 17 |  | 
|  | 18 | declare -a arr=( | 
|  | 19 | # Commands to be outputted into individual files | 
|  | 20 | # Format: "File name" "Command" | 
|  | 21 | "Build_info.txt"            "cat /etc/version" | 
|  | 22 | "FW_level.txt"              "cat /etc/os-release" | 
|  | 23 | "BMC_OS.txt"                "uname -a" | 
|  | 24 | "BMC_uptime.txt"            "uptime" | 
|  | 25 | "BMC_disk_usage.txt"        "df -hT" | 
|  | 26 |  | 
|  | 27 | "systemctl_status.txt"      "systemctl status | cat" | 
|  | 28 | "failed_services.txt"       "systemctl --failed" | 
|  | 29 | "host_console.txt"          "cat /var/log/obmc-console.log" | 
|  | 30 |  | 
|  | 31 | "BMC_proc_list.txt"         "top -n 1 -b" | 
|  | 32 | "BMC_journalctl.txt"        "journalctl --no-pager" | 
|  | 33 | "BMC_dmesg.txt"             "dmesg" | 
|  | 34 | "BMC_procinfo.txt"          "cat /proc/cpuinfo" | 
|  | 35 | "BMC_meminfo.txt"           "cat /proc/meminfo" | 
|  | 36 |  | 
|  | 37 | # Copy all content from these directories into directories in the .tar | 
|  | 38 | # Format: "Directory name" "Directory to copy" | 
|  | 39 | "obmc"                      "/var/lib/obmc/" | 
| Jayanth Othayoth | 5cca05a | 2017-07-13 06:00:47 -0500 | [diff] [blame^] | 40 | "core"                      "/var/lib/systemd/coredump" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 41 | ) | 
|  | 42 |  | 
|  | 43 | dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" | 
|  | 44 | dest="/tmp" | 
| Jayanth Othayoth | ab741df | 2017-07-13 05:48:33 -0500 | [diff] [blame] | 45 | enable_dump=false | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 46 |  | 
|  | 47 | while [[ $# -gt 0 ]]; do | 
|  | 48 | key="$1" | 
|  | 49 | case $key in | 
|  | 50 | -d|--dir) | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 51 | mkdir -p "$2" | 
|  | 52 | if [ $? -eq 0 ]; then | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 53 | dest="$2" | 
|  | 54 | else | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 55 | echo "Failed to create the destination directory specified." | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 56 | break | 
|  | 57 | fi | 
|  | 58 | shift 2 | 
|  | 59 | ;; | 
| Jayanth Othayoth | ab741df | 2017-07-13 05:48:33 -0500 | [diff] [blame] | 60 | -e|--enable_dump) | 
|  | 61 | enable_dump=true | 
|  | 62 | shift | 
|  | 63 | ;; | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 64 | -h|--help) | 
|  | 65 | echo "$help" | 
|  | 66 | exit | 
|  | 67 | ;; | 
|  | 68 | *) | 
|  | 69 | echo "Unknown option $1. Display available options with -h or --help" | 
|  | 70 | exit | 
|  | 71 | ;; | 
|  | 72 | esac | 
|  | 73 | done | 
|  | 74 |  | 
|  | 75 | echo "Using destination directory $dest" | 
|  | 76 |  | 
| Jayanth Othayoth | ab741df | 2017-07-13 05:48:33 -0500 | [diff] [blame] | 77 | if [ $enable_dump = true ]; then | 
|  | 78 | id=$(basename $dest) | 
|  | 79 | printf -v f_id "%08d" $id | 
|  | 80 | dir=$"obmcdump_"$f_id"_$(date +"%s")" | 
|  | 81 | fi | 
|  | 82 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 83 | mkdir -p "$dest/$dir" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 84 |  | 
|  | 85 | for ((i=0;i<${#arr[@]};i+=2)); do | 
|  | 86 | if [ -d "${arr[i+1]}" ]; then | 
|  | 87 | echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..." | 
|  | 88 | mkdir "$dest/$dir/${arr[i]}" | 
|  | 89 | cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]} | 
|  | 90 | else | 
|  | 91 | echo "Collecting ${arr[i]}..." | 
|  | 92 | ${arr[i+1]} >> "$dest/$dir/${arr[i]}" | 
|  | 93 | fi | 
|  | 94 | done | 
|  | 95 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 96 | tar -cf "$dest/$dir.tar" -C $dest $dir | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 97 | echo "Contents in $dest/$dir.tar" | 
|  | 98 |  | 
|  | 99 | rm -r "$dest/$dir" |