Below is my current Bash code for going to a list of boxes from the file "testhost", it will go to each host listed in testhost and gather information for my wiki and print it out to a log file in Wiki format. I am trying to do a couple of things with this code below, for instance I would like to be able to cut back the number of times I have to SSH to a box, if I could set multiple variables at once that would be great.
Secondly I would like to set local variables on the SSH'd host, then run some if statements and return the value, I'm having a little trouble with that.
Any tips on how you would approach this would be great.
#!/bin/bash
for i in `cat testhost`
do
HOSTZ=`ssh $i "hostname" |cut -d. -f1`
printf "^ $HOSTZ ^^^^^^\n" >> WikiMike
echo "^ Make ^ Model ^ CPU ^ Number of Cores ^ Memory ^ Serial Number ^" >> WikiMike
MAKE=`ssh $i "dmesg" |grep ProL |awk 'NR==1' |awk '{print $2}'`
MODEL=`ssh $i "dmesg" |grep ProL |awk 'NR==1' |awk '{print $3,$4,$5}' |sed 's/[,]//g'`
CPUZ=`ssh $i "cat /proc/cpuinfo" |grep 'model name' |awk 'NR==1' |awk '{print $7,$8,$9}'`
COREZ=`ssh $i "cat /proc/cpuinfo" |grep processor |tail -n 1 |awk '{print $3}'`
COREZ=`expr $COREZ + 1`
MEMZ=`ssh $i "cat /proc/meminfo" |head -n 1 |awk '{print $2}'`
MEMZ=`expr $MEMZ / 1024 / 1024`
SERIAL=`ssh $i "lshal" |grep system.hardware.serial |awk '{print $3}' |tr -d "'"`
echo "| $MAKE | $MODEL | $CPUZ | $COREZ | $MEMZ gb | $SERIAL | " >> WikiMike
echo "^ Interface ^ Name ^ MAC ^ IP ^ Broadcast ^ Mask ^" >> WikiMike
ssh $i "/sbin/ifconfig" |egrep "eth|inet|bond" |sed 's/eth/~eth/g' |tr "\012" " " |tr "~" "\012" |grep inet |awk '{print "| | ",$1," | "$5," | ",$7," | ",$8," | ",$9," |"}' >> WikiMike
printf "\n\n" >> WikiMike
done