diff --git a/scripts/iiab-diagnostics b/scripts/iiab-diagnostics index 19fde7684..31bc522e6 100755 --- a/scripts/iiab-diagnostics +++ b/scripts/iiab-diagnostics @@ -1,12 +1,13 @@ #!/bin/bash -# create a diagnostic collection, and documet OS settings +# Create a diagnostic collection, and document OS settings. +# PLEASE SEE iiab-diagnostics.README.md read -p "\n\nPlease provide a name or nickname: (8 characters or less, no spaces) " who if [ -z "$who" ]; then who="noname" fi -# Build up a meaningful name for transmission back to the development team +# Build up a meaningful name for transmission to dev team(s) OS_VER=`cat /etc/iiab/iiab.env | grep OS_VER | cut -d'=' -f2` pushd /opt/iiab/iiab HASH=`git log --pretty=format:'g%h' -n 1` @@ -18,55 +19,56 @@ diagnostics_name=${OS_VER}-$YMD-$who outfile=$diagnostics_name.$$ VARS_VALUES=/tmp/all-vars -# record all the ansible variables -pushd /opt/iiab/iiab > /dev/null +# Record all Ansible variables +# pushd /opt/iiab/iiab > /dev/null # ./runrole all-vars $VARS_VALUES -popd > /dev/null +# popd > /dev/null # cat files in this direcory -function cat_dir(){ - echo >>/tmp/$outfile - echo "=IIAB=====================================================" >> /tmp/$outfile - if [ -d "$1" ];then - echo "Printing files in $1 directory" >> /tmp/$outfile - echo >>/tmp/$outfile - filelist=$(ls $1) - if [ ! -z "$filelist" ]; then - pushd $1 - for f in `ls *`;do - echo "Printing contents of $f" >> /tmp/$outfile - echo >>/tmp/$outfile - cat $f | iconv -t UTF-8//IGNORE >> /tmp/$outfile +function cat_dir() { + echo >> /tmp/$outfile + echo "=IIAB=====================================================" >> /tmp/$outfile + if [ -d "$1" ]; then + echo "Printing files in $1 directory" >> /tmp/$outfile + echo >> /tmp/$outfile + filelist=$(ls $1) + if [ ! -z "$filelist" ]; then + pushd $1 + for f in `ls *`; do + echo "Printing contents of $f" >> /tmp/$outfile + echo >>/tmp/$outfile + cat $f | iconv -t UTF-8//IGNORE >> /tmp/$outfile done - popd - fi - else - echo "Directory $1 does not exist" >> /tmp/$outfile - fi + popd + fi + else + echo "Directory $1 does not exist" >> /tmp/$outfile + fi } -function cat_file(){ - echo >>/tmp/$outfile - echo "=IIAB====================================================" >> /tmp/$outfile - if [ -f $1 ];then - echo "Printing contents of $1" >> /tmp/$outfile - echo >>/tmp/$outfile - if [ $# -eq 2 ];then - echo "Printing last 100 lines" >> /tmp/$outfile - tail -100 $1 | iconv -t UTF-8//IGNORE >> /tmp/$outfile - else - cat $1 | iconv -t UTF-8//IGNORE >> /tmp/$outfile - fi - else - echo "File $1 does not exists" >> /tmp/$outfile - fi +function cat_file() { + echo >> /tmp/$outfile + echo "=IIAB====================================================" >> /tmp/$outfile + if [ -f $1 ]; then + echo "Printing contents of $1" >> /tmp/$outfile + echo >> /tmp/$outfile + if [ $# -eq 2 ]; then + echo "Printing last 100 lines" >> /tmp/$outfile + tail -100 $1 | iconv -t UTF-8//IGNORE >> /tmp/$outfile + else + cat $1 | iconv -t UTF-8//IGNORE >> /tmp/$outfile + fi + else + echo "File $1 does not exists" >> /tmp/$outfile + fi } -function cat_file_list(){ - for f in $(cat filelist);do - cat_file $f - done +function cat_file_list() { + for f in $(cat filelist); do + cat_file $f + done } + # collect all the network info in one place cat << EOF > /tmp/diagnostics_script #!/bin/bash @@ -89,11 +91,11 @@ echo "=IIAB=====================================================" echo Checking for information about raspberry pi base image echo Output from command 'cat /etc/rpi-issue' echo -if [ -f /etc/rpi-issue ];then +if [ -f /etc/rpi-issue ]; then cat /etc/rpi-issue echo "stage2 = lite; stage5 = desktop SEE https://github.com/RPi-Distro/pi-gen#stage-anatomy" else - echo "not a raspberry pi" + echo "Not a Raspberry Pi." fi echo "=IIAB=====================================================" echo "/sbin/brctl show" @@ -111,10 +113,10 @@ echo iptables-save echo echo "=IIAB=====================================================" -if [ -f /.iiab-image ];then -echo "Output of /bin/cat /.iiab-image command." -echo -cat /.iiab-image +if [ -f /.iiab-image ]; then + echo "Output of /bin/cat /.iiab-image command." + echo + cat /.iiab-image else echo /.iiab-image does not exist. fi @@ -159,10 +161,10 @@ cat_file /opt/iiab/iiab-admin-console/admin-install.log last #fi mkdir -p /etc/iiab/diagnostics -if [ ! -z $diagnostics_name ];then - pushd /tmp > /dev/null - cp /tmp/$outfile /etc/iiab/diagnostics/ - popd > /dev/null - #rm -rf /tmp/$outfile - exit 0 +if [ ! -z $diagnostics_name ]; then + pushd /tmp > /dev/null + cp /tmp/$outfile /etc/iiab/diagnostics/ + popd > /dev/null + #rm -rf /tmp/$outfile + exit 0 fi