FileSystem Alert
Publicado por Leonardo Berbert Gomes (última atualização em 29/07/2020)
[ Hits: 904 ]
Homepage: https://www.linkedin.com/in/leoberbert
Script para monitoramento de diversos filesystems e envio de e-mail sem uso de autenticação.
#!/bin/perl # use Sys::Hostname; use Data::Dumper; use Time::Local; # ($sec,$min,$hour,$day,$month,$year) = (localtime(time))[0,1,2,3,4,5]; $month +=1;$year +=1900; if ($day =~ /^\d$/) { $day = "0" . $day;} if ($min =~ /^\d$/) { $min = "0" . $min;} if ($sec =~ /^\d$/) { $sec = "0" . $sec;} if ($hour =~ /^\d$/) { $hour = "0" . $hour;} if ($month =~ /^\d$/) { $month = "0" . $month;} my $treshold = 85; ## Altere aqui pelo valor que irá gerar o alerta my $fs = "/home,/var/log"; ## Inclua todos os FileSystem que deseja monitorar my @fs = split /,/, $fs; my @list = (); for my $i (0 .. $#fs){ push @list, qr/^$fs[$i]/; } open (COMMAND,"df -h |"); while ($line = <COMMAND>){ chomp $line; if ($line =~ /^Filesystem/) {next}; my @array = split /\s+/, $line; $used_perc = @array[4]; $mount_point = @array[5]; $used_perc =~s/\%//g; if ($mount_point ~~ @list) { if ($used_perc >= $treshold) { $hash{"FileSystem: $mount_point \t| used: $used_perc%"}++; } } } my $mail_file = "mail" . "_" . $year . $month . $day . $hour . $min . $sec . ".tmp"; open(OUT,">$mail_file") or die "Can't open : $!"; foreach $I ( sort keys %hash) { print OUT "$I\n"; } close(OUT); if ( -z $mail_file ) { unlink $mail_file; } else { my $emails="leoberbert\@uol.com.br,leoberbert\@gmail.com.br"; ## Inclua todos os email que irão receber o alerta my $hostname = hostname(); my $server = "meuserver_smtp_sem_autenticacao.com.br:25"; ## Altere pelo seu servidor SMTP my $message = "Filesystem $mount_point acima do Treshold. "; system("cat $mail_file | mailx -S smtp=$server -s \"Alerta: Espaço em disco do servidor $hostname está no limite\" -v $emails"); unlink $mail_file; }
Diminuir ou aumentar o brilho de notebook
Nenhum comentário foi encontrado.
Atualizar o macOS no Mac - Opencore Legacy Patcher
Crie alias para as tarefas que possuam longas linhas de comando - bash e zsh
Criando um gateway de internet com o Debian
Configuração básica do Conky para mostrar informações sobre a sua máquina no Desktop
Aprenda a criar músicas com Inteligência Artificial usando Suno AI
Instalando Zoom Client no Ubuntu 24.04 LTS
Instalando Zoom Client no Fedora 40
Instalando Navegador Firefox no Debian 12
Bloqueando propagandas no Youtube e outros sites com o uBlocker Origin