Created
May 19, 2014 00:03
-
-
Save vhogemann/b655f75ce4c67e7f16c2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /bin/bash | |
# String retornada pelo reg.exe em caso de update com sucesso | |
REG_UP_OK="The operation completed successfully" | |
# Checa se existe lista de hosts não atualizados | |
if [ -e mortos.txt ]; then | |
# Se existe, renomeia para tmp.txt e o utiliza... | |
# criando uma nova lista para as maquinas que não atualizarem | |
mv mortos.txt tmp.txt | |
HOST_LIST="tmp.txt" | |
else | |
# Se não, usa o arquivo com a lista completa de hosts | |
HOST_LIST="hosts.txt" | |
fi | |
for f in `cat $HOST_LIST`; do | |
echo "checando host $f" | |
# Hack horrivel para fazer o ping do windows funcionar semi-decentemente | |
if [ `ping -n 1 -w 2000 $f | grep Re | cut -d ' ' -f 1` = "Reply" ]; then | |
# Se o host estiver de pé, então... | |
echo "host $f está vivo" | |
# Verifica se o patch já foi aplicado ou não... | |
# Note que o REG.EXE não funciona direito sob o Cygwin | |
# Então precisamos utilizar o CMD.EXE para invoca-lo | |
QUERY_REG=`cmd.exe /C 'reg.exe query Software\Policies\Microsoft\Windows\WindowsUpdate\ \\$f' | grep REG_DWORD | tail -n 1 | cut -c 23-` | |
echo $QUERY_REG | |
if [ -z "$QUERY_REG" ] || [ "$QUERY_REG" != "http://smsaifdell1.saude.rio.rj.gov.br" ]; then | |
# Se não, aplica o patch de registro... | |
UPDATE_CMD=`cmd.exe /C 'reg import wupdate.reg \\\\$f' | grep The` | |
if [ "$UPDATE_CMD" != "$REG_UP_OK" ]; then | |
# Havendo erros coloca o host no arquivo mortos.txt para ser atualizado mais tarde | |
echo "Ocorreu um erro, tente mais tarde!" | |
echo $f >> mortos.txt | |
else | |
# Se retornar OK, loga no arquivo sucesso.txt | |
echo "Completado com sucesso!" | |
echo $f >> sucesso.txt | |
fi | |
fi | |
else | |
# Se o host estiver down, atualiza o mortos.txt | |
echo "host $f está morto" | |
echo $f >> mortos.txt | |
fi | |
done | |
# Se existir, remove o arquivo temporário de hosts | |
if [ -e tmp.txt ]; then | |
rm -f tmp.txt | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment