1
0
Fork 0
mirror of https://github.com/iiab/iiab.git synced 2025-03-09 15:40:17 +00:00

bash readability of iiab-diagnostics

This commit is contained in:
A Holt 2019-06-22 16:50:49 -04:00 committed by GitHub
parent e70511971a
commit 49f44b37e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

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