| 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. | 
 | 12 |    -h, --help             Display this help text and exit. | 
 | 13 | ' | 
 | 14 |  | 
 | 15 | declare -a arr=( | 
 | 16 | # Commands to be outputted into individual files | 
 | 17 | # Format: "File name" "Command" | 
 | 18 |       "Build_info.txt"            "cat /etc/version" | 
 | 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 | ) | 
 | 38 |  | 
 | 39 | dir=$"ffdc_$(date +"%Y-%m-%d_%H-%M-%S")" | 
 | 40 | dest="/tmp" | 
 | 41 |  | 
 | 42 | while [[ $# -gt 0 ]]; do | 
 | 43 |   key="$1" | 
 | 44 |   case $key in | 
 | 45 |     -d|--dir) | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame^] | 46 |       mkdir -p "$2" | 
 | 47 |       if [ $? -eq 0 ]; then | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 48 |         dest="$2" | 
 | 49 |       else | 
| Jayanth Othayoth | 599c7af | 2017-07-09 21:18:32 -0500 | [diff] [blame^] | 50 |         echo "Failed to create the destination directory specified." | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 51 |         break | 
 | 52 |       fi | 
 | 53 |       shift 2 | 
 | 54 |       ;; | 
 | 55 |     -h|--help) | 
 | 56 |       echo "$help" | 
 | 57 |       exit | 
 | 58 |       ;; | 
 | 59 |     *) | 
 | 60 |       echo "Unknown option $1. Display available options with -h or --help" | 
 | 61 |       exit | 
 | 62 |       ;; | 
 | 63 |   esac | 
 | 64 | done | 
 | 65 |  | 
 | 66 | echo "Using destination directory $dest" | 
 | 67 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 68 | mkdir -p "$dest/$dir" | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 69 |  | 
 | 70 | for ((i=0;i<${#arr[@]};i+=2)); do | 
 | 71 |   if [ -d "${arr[i+1]}" ]; then | 
 | 72 |     echo "Copying contents of ${arr[i+1]} to directory ./${arr[i]} ..." | 
 | 73 |     mkdir "$dest/$dir/${arr[i]}" | 
 | 74 |     cp -r ${arr[i+1]}/* $dest/$dir/${arr[i]} | 
 | 75 |   else | 
 | 76 |     echo "Collecting ${arr[i]}..." | 
 | 77 |     ${arr[i+1]} >> "$dest/$dir/${arr[i]}" | 
 | 78 |   fi | 
 | 79 | done | 
 | 80 |  | 
| Jayanth Othayoth | a19440d | 2017-06-20 06:53:47 -0500 | [diff] [blame] | 81 | tar -cf "$dest/$dir.tar" -C $dest $dir | 
| Michael Tritz | 3e3f28b | 2017-01-18 13:54:42 -0600 | [diff] [blame] | 82 | echo "Contents in $dest/$dir.tar" | 
 | 83 |  | 
 | 84 | rm -r "$dest/$dir" |