#!/bin/bash
clear;

rm tableau.txt
touch tableau.txt

#crÃation de la table HTML
echo "<table>" >> tableau.txt

rm temp.txt
touch temp.txt

echo "<tr>" >> tableau.txt
echo "<th>hostname</th>"        >> tableau.txt
echo "<th>IP</th>"              >> tableau.txt
echo "<th>Mac address</th>"     >> tableau.txt
echo "<th>CPU's model</th>"     >> tableau.txt
echo "<th>RAM size</th>"        >> tableau.txt
echo "<th>disk capacity</th>"   >> tableau.txt
echo "</tr>" >> tableau.txt

for i in `seq 23 56`;
do
	touch temp.txt
	echo "***************** testing ip 10.4.69.$i *****************"
	#le host
	a=$(ssh 10.4.69.$i 'hostname')
	#echo "hostname: $a" 

	#pour l'adresse ip
	ssh 10.4.69.$i '/sbin/ifconfig > ifconfig.txt' # on enregistre la config dans un texte
	grep "inet adr:10" ifconfig.txt > temp.txt     # on récupère la ligne de l'adresse ip dans un autre texte
	b=$(cut -c 20-29 temp.txt)                     # on récupère les caractères recherchés dans la variable
	#echo "IP: $b"

	#pour l'adresse MAC
	grep "HWaddr" ifconfig.txt > temp.txt
	c=$(cut -c 39-55 temp.txt)
	#echo "Mac address: $c"

	#le model du CPU
	ssh 10.4.69.$i 'cat /proc/cpuinfo > cpuinfo.txt'
	grep "cpu" cpuinfo.txt > temp.txt
	e=$(cut -c 8-37 temp.txt)
	#echo "CPU's model: $e"

	#la taille de la RAM
	ssh 10.4.69.$i 'cat /proc/meminfo > meminfo.txt'
	grep "MemTotal" meminfo.txt > temp.txt
	g=$(cut -c 16-25 temp.txt)
	#echo "RAM size: $g"

	#la capacitÃ©du DD
	ssh 10.4.69.$i 'df -h > disk.txt'
	grep "/dev/hda1" disk.txt > temp.txt
	j=$(cut -c 23-26 temp.txt)
	#echo "disk capacity: $j"
	rm temp.txt

if [ $a != '' ]; then
#une balise de ligne pour le tableau
echo "<tr>" >> tableau.txt

echo "<td>$a</td>"   >> tableau.txt
echo "<td>$b</td>"   >> tableau.txt
echo "<td>$c</td>"   >> tableau.txt
echo "<td>$e</td>"   >> tableau.txt
echo "<td>$g</td>"   >> tableau.txt
echo "<td>$j</td>"   >> tableau.txt

#on ferme la balise de ligne
echo "</tr>" >> tableau.txt
fi

done
rm ifconfig.txt
rm temp.txt
rm cpuinfo.txt
rm meminfo.txt
rm disk.txt
#on ferme la table HTML
echo "</table>" >> tableau.txt

mv tableau.txt ~/public_html/network_infos.html


