Status server in motd
De MochilaWiki
Revisão de 21h35min de 2 de janeiro de 2012 por Banto Palmarino (discussão | contribs) (Criou página com '# abra um novo arquivo com o nome/endereço <source lang="bash"> # nano -w /usr/local/bin/systemstats.sh </source> # com o conteúdo <source lang="bash"> #!/bin/bash # # Server...')
- abra um novo arquivo com o nome/endereço
# nano -w /usr/local/bin/systemstats.sh
- com o conteúdo
#!/bin/bash
#
# Server Status Script
# Version 0.1.3 m
# Updated: July 26th 2011 m
CPUTIME=$(ps -eo pcpu | awk 'NR>1' | awk '{tot=tot+$1} END {print tot}')
CPUCORES=$(cat /proc/cpuinfo | grep -c processor)
UP=$(echo `uptime` | awk '{ print $3 " " $4 }')
echo "
System Status
Updated: `date`
- Server Name = `hostname`
- Public IP = `dig +short myip.opendns.com @resolver1.opendns.com`
- OS Version = `cat /etc/redhat-release`
- Load Averages = `cat /proc/loadavg`
- System Uptime = `echo $UP`
- Platform Data = `uname -orpi`
- CPU Usage (average) = `echo $CPUTIME / $CPUCORES | bc`%
- Memory free (real) = `free -m | head -n 2 | tail -n 1 | awk {'print $4'}` Mb
- Memory free (cache) = `free -m | head -n 3 | tail -n 1 | awk {'print $3'}` Mb
- Swap in use = `free -m | tail -n 1 | awk {'print $3'}` Mb
- Disk Space Used = `df / | awk '{ a = $4 } END { print a }'`
" > /etc/motd
# End of script
- deixe o script como executável
# chmod +x /usr/local/bin/systemstats.sh
- acrescente no crontab para rodar a cada cinco minutos
# nano -w /etc/crontab
# Status Script
*/5 * * * * root /usr/local/bin/systemstats.sh
- rodar manualmente
<source lang="bash">
- /usr/local/bin/systemstats.sh
<source lang="bash">
Referência: