CheckScript

Da GazziNet.
Vai alla navigazione Vai alla ricerca
#!/bin/bash
## Versione 1.0 - Christian Gozzi - Partech
## Script per esecuzione ricorsiva su vari host di una serie di comandi.
LOG_FILE=logfile.txt
LOG_OK=logmachineok.txt
LOG_NONOK=logmachinenook.txt
LOG_AGENTHOST=listavmpulire.txt
LOG_PULIZIE=logpulizie.txt
LOG_CHECK=check.txt
rm -f ${LOG_NONOK}
rm -f ${LOG_FILE}
rm -f ${LOG_OK}
rm -f ${LOG_AGENTHOST}
rm -f ${LOG_PULIZIE}
fileItemString=$(cat  lista.txt |tr "\n" " ")
fileItemArray=($fileItemString)
# Iterate the string array using for loop
for val in ${fileItemArray[@]}; do
  echo $val
( ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$val cat /etc/fstab | grep "cifs\|nfs") & pid=$!
( sleep 5 && kill -HUP $pid ) 2>/dev/null & watcher=$!
if wait $pid 2>/dev/null; then
   echo "SSH ok su: $val"
       echo $val>> check.txt
       echo "---" >> check.txt
       ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null root@$val cat /etc/fstab | grep "cifs\|nfs"  >> check.txt
       echo "---" >> check.txt
   pkill -HUP -P $watcher
   wait $watcher
else
   echo "SSH error su: $val"
       echo $val>> ${LOG_NONOK}
fi
done