Skip to content
Snippets Groups Projects
Verified Commit 504883e5 authored by David Beniamine's avatar David Beniamine
Browse files

Handle multiples IPs per clients #26

parent 64acce47
Branches master
No related tags found
No related merge requests found
......@@ -16,16 +16,23 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
getip(){
mainlog="/var/log/`basename $0`_`date +%Y%m%d-%H%M`"
getips(){
awk '/^lease/{IP=$2} /hardware ethernet/{gsub(";","",$3);if($3 == "'$1'"){print IP}}' \
< /var/lib/dhcp/dhcpd.leases | tail -n 1
< /var/lib/dhcp/dhcpd.leases | sort -u
}
runcmd(){
host=$1
logfile=/tmp/$$-$host.log
shift
echo "Runnig $@ on $host"
ssh -o StrictHostKeychecking=no root@$host $@
echo "Runnig $@ on $host" | tee $logfile
ssh -o StrictHostKeychecking=no root@$host $@ | tee $logfile
}
log(){
echo $@ | tee -a $mainlog
}
# Switch to lametros repository
......@@ -39,29 +46,77 @@ wait_time=120
wait_step=5
cmd="cd /opt/primtux-eole/; export HTTPS_PROXY='http://dnsproxy:3128'; git pull; ./upgrade-session.sh $1"
declare -A HOSTS
declare -A IPTOMACS
declare -A DOWNS
while read date mac name
do
# Boot machine
wakeonlan -i $broadcast "$mac"
MACS+=" $mac"
if [ ! -z "$date" ]
then
HOSTS[$mac]=$name
log "Trying to boot $name ($mac)"
for i in seq 1 3
do
wakeonlan -i $broadcast "$mac"
done
sleep 5
MACS+=" $mac"
fi
done < $conf_file
# Wait for boot
echo ""
log "Wakeonlan sent, waiting"
while [ $wait_time -gt 0 ]
do
echo -ne "Waiting for boot, remaining $wait_time seconds\r"
log -ne "Waiting for boot, remaining $wait_time seconds\r"
sleep $wait_step
wait_time=$(($wait_time - $wait_step))
done
echo -e "\nWaiting finished"
log -e "\nWaiting finished"
# Running command
for mac in $MACS
do
ip=$(getip $mac)
runcmd $ip $cmd &
PIDS="$PIDS $!"
for ip in $(getips $mac)
do
IPTOMACS[$ip]=$mac
runcmd $ip $cmd &
PIDS="$PIDS $!"
done
done
# wait all pids
wait $PIDS
for pid in $PIDS
do
wait $pid
done
# Retrieving logs
for f in /tmp/$$-*
do
ip=$(echo $f | cut -d '-' -f 2- | sed 's/\.log$//')
mac=${IPTOMACS[$ip]}
name=${HOSTS[$mac]}
log "===== Begin host $name ($mac - $ip) ===="
cat $f >> $mainlog
log "===== End host $name ===="
if [ $(wc -l $f | awk '{print $1}') -gt 0 ]
then
DOWNS[$mac]=$name
fi
rm $f
done
# Listing down hosts
if [ ${#DOWNS[@]} -eq 0 ]
then
log "All ${#HOSTS[@]} hosts answered"
else
log "On a total of ${#HOSTS[@]} hosts, ${#DOWNS[@]} are still down:"
for mac in ${!DOWNS[@]}
do
log -e "\t* ${DOWNS[$mac]} ($mac)"
done
fi
log "Output written to $mainlog"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment