I have a few raspberry pi's creating reverse ssh tunnels on an ssh server. From that server I can connect on all the raspberry pi's. I want to create a bash script that will run on this ssh server, collect some information from all the raspberry pi's and generate an html report. I have something working already, it only connects on a single raspberry pi. I need to somehow loop it, so that it will connect on all the raspberry pi's.
The variable that must be looped somehow is $port because each raspberry pi connects on a unique port on the ssh server, and its from that port that the server can connect back on the raspberry pi's.
I'm guessing it will have to be something like... for each $port in ports.txt perform the following commands and put the results in the html table
#!/bin/bash
cpu="$(ssh -o StrictHostKeyChecking=no $user@localhost -p $port echo $[100-$(vmstat|tail -1|awk '{print $15}')]"%")"
dsk="$(ssh -o StrictHostKeyChecking=no $user@localhost -p $port df -h /dev/mmcblk0p2 | awk 'NR>1{print $5}')"
mem="$(ssh -o StrictHostKeyChecking=no $user@localhost -p $port free | grep -e-/+ | awk '{print $3/($3+$4) * 100.0 ''}' | cut -d '.' -f1)"
tmp="$(ssh -o StrictHostKeyChecking=no $user@localhost -p $port /opt/vc/bin/vcgencmd measure_temp | sed -e 's/temp=//')"
mda="$(ssh -o StrictHostKeyChecking=no $user@localhost -p $port /bin/ls -R -l /$user/media | /usr/bin/wc -l)"
echo '<html>'
echo '<head>'
echo '<title>BeatBox Report</title>'
echo '</head>'
echo '<body>'
echo '<table border="1" align="center">'
echo '<tr>'
echo '<td></td>'
echo '<td>CPU Usage</td>'
echo '<td>Disk Usage</td>'
echo '<td>Memory Usage</td>'
echo '<td>Temperature</td>'
echo '<td>Media Count</td>'
echo '</tr>'
echo '<tr>'
echo '<td>Client001</td>'
echo "<td align="center">$cpu</td>"
echo "<td align="center">$dsk</td>"
echo "<td align="center">$mem%</td>"
echo "<td align="center">$tmp</td>"
echo "<td align="center">$mda</td>"
echo '</tr>'
echo '<tr>'
echo '<td>Client002</td>'
echo "<td align="center">$cpu</td>"
echo "<td align="center">$dsk</td>"
echo "<td align="center">$mem%</td>"
echo "<td align="center">$tmp</td>"
echo "<td align="center">$mda</td>"
echo '</tr>'
echo '<tr>'
echo '<td>Client003</td>'
echo "<td align="center">$cpu</td>"
echo "<td align="center">$dsk</td>"
echo "<td align="center">$mem%</td>"
echo "<td align="center">$tmp</td>"
echo "<td align="center">$mda</td>"
echo '</tr>'
echo '</table>'
echo '</body>'
echo '</html>'
for port in $(cat ports.txt); do
and at the end of it, insert linedone
. As long as all ports are in ports.txt file, you are good to go – MelBurslan Apr 06 '16 at 17:08