diff --git a/registry/scripts/upgrade_all.sh b/registry/scripts/upgrade_all.sh index 4da61b7ae10182f77087e01f9ae0649ac846258f..13fe9cb33ef92aa66723c148d8881df845e6c0fd 100755 --- a/registry/scripts/upgrade_all.sh +++ b/registry/scripts/upgrade_all.sh @@ -16,6 +16,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +mainlog="/var/log/`basename $0`_`date +%Y%m%d-%H%M`" + getip(){ awk '/^lease/{IP=$2} /hardware ethernet/{gsub(";","",$3);if($3 == "'$1'"){print IP}}' \ < /var/lib/dhcp/dhcpd.leases | tail -n 1 @@ -23,9 +25,14 @@ getip(){ 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 @@ -43,19 +50,20 @@ cmd="cd /opt/primtux-eole/; export HTTPS_PROXY='http://dnsproxy:3128'; git pull; while read date mac name do # Boot machine + log "Trying to boot $mac" wakeonlan -i $broadcast "$mac" MACS+=" $mac" 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" | tee $mainlog sleep $wait_step wait_time=$(($wait_time - $wait_step)) done -echo -e "\nWaiting finished" +log -e "\nWaiting finished" for mac in $MACS do @@ -65,3 +73,13 @@ do done # wait all pids wait $PIDS + +# Retrieving logs +for f in /tmp/$$-* +do + host=$(echo $f | cut -d '-' -f 2-) + log "===== Begin host $host ====" + cat $f >> $mainlog + log "===== End host $host ====" +done +log "Output written to $mainlog"