| 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: | 
 | 10 |    -d, --dir <directory>  Specify destination directory. Defaults to /tmp if | 
 | 11 |                           invalid or unspecified. | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 12 |    -D, --disable_dreport  Disable dreport based dump collection | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 13 |    -h, --help             Display this help text and exit. | 
 | 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" | 
 | 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/" | 
| Jayanth Othayoth | 5cca05a | 2017-07-13 06:00:47 -0500 | [diff] [blame] | 37 |       "core"                      "/var/lib/systemd/coredump" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 38 | ) | 
 | 39 |  | 
 | 40 | dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" | 
 | 41 | dest="/tmp" | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 42 | disable_dreport=false | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 43 |  | 
 | 44 | while [[ $# -gt 0 ]]; do | 
 | 45 |   key="$1" | 
 | 46 |   case $key in | 
 | 47 |     -d|--dir) | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 48 |       mkdir -p "$2" | 
 | 49 |       if [ $? -eq 0 ]; then | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 50 |         dest="$2" | 
 | 51 |       else | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame] | 52 |         echo "Failed to create the destination directory specified." | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 53 |         break | 
 | 54 |       fi | 
 | 55 |       shift 2 | 
 | 56 |       ;; | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 57 |     -D|--disable_dreport) | 
 | 58 |       disable_dreport=true | 
 | 59 |       shift | 
 | 60 |       ;; | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 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 | 
 | 70 | done | 
 | 71 |  | 
 | 72 | echo "Using destination directory $dest" | 
 | 73 |  | 
| Jayanth Othayoth | d816611 | 2017-11-02 22:52:18 -0500 | [diff] [blame] | 74 | if [ $disable_dreport = false ]; then | 
 | 75 |   dreport -d $dest -v | 
 | 76 |   exit | 
 | 77 | fi | 
 | 78 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 79 | mkdir -p "$dest/$dir" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 80 |  | 
 | 81 | for ((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 | 
 | 90 | done | 
 | 91 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 92 | tar -cf "$dest/$dir.tar" -C $dest $dir | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 93 | echo "Contents in $dest/$dir.tar" | 
 | 94 |  | 
 | 95 | rm -r "$dest/$dir" |