o arquivo txt do monitoramento_hardware.txt não aparece apos ser rodado o script
#!/bin/bash
LOG_DIR="monitoramento_sistema"
mkdir -p $LOG_DIR
function monitorar_logs() {
grep -E "fail(ed)?|error|denied|unauthorized" /var/log/syslog | awk '{print $1, $2, $3, $4, $5, $6, $7}' > $LOG_DIR/monitoramento_logs_sistema.txt
grep -E "fail(ed)?|error|denied|unauthorized" /var/log/syslog | awk '{print $1, $2, $3, $4, $5, $6, $7}' > $LOG_DIR/monitoramento_logs_auth.txt
}
function monitorar_rede() {
if ping -c 1 8.8.8.8 > /dev/null; then
echo "$(date): Conectividade ativa" >> $LOG_DIR/monitoramento_rede.txt
else
echo "$(date): Sem conexao com a internet" >> $LOG_DIR/monitoramento_rede.txt
fi
if curl -s --head https://www.alura.com.br/ | grep "
HTTP/2 200" > /dev/null; then
echo "$(date): Conexao com a alura bem-sucedida." >> $LOG_DIR/monitoramento_rede.txt
else
echo "$(date): Falha ao conectar com a alura." >> $LOG_DIR/monitoramento_rede.txt
fi
}
function monitorar_disco() {
echo "$(date)" > $LOG_DIR/monitoramento_disco.txt
df -h | grep -v "snapfuse" | awk '$5+0 > 30 {print $1 " esta com " $5 " de uso."}' >> $LOG_DIR/monitoramento_disco.txt
echo "uso de disco no dir principal:" >> $LOG_DIR/monitoramento_disco.txt
du -sh /home/uriid >> $LOG_DIR/monitoramento_disco.txt
}
function monitorar_hardware() {
echo "$(date)" > $LOG_DIR/monitoramento_hardware.txt
free -h | grep Mem | awk '{print "Total: " $2 ", Usada: " $3 ", Livre: " $4}' >> $LOG_DIR/monitoramento_hardware.txt
}
function executar_monitoramento() {
monitorar_logs
monitorar_rede
monitorar_disco
monitorar_hardware
}
echo "Iniciando monitoramento..."
executar_monitoramento
echo "Monitoramento concluído. Verifique os logs em $LOG_DIR"