Created
February 9, 2010 20:39
-
-
Save pklaus/299632 to your computer and use it in GitHub Desktop.
Write a Linux Server Resource Report to Log Files Automatically
This file contains 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/sh | |
# /root/bin/get_resources.sh | |
echo -n "Server Resource Report at `/bin/hostname` on " | |
date "+%Y/%m/%d %T" | |
echo | |
echo "[dmesg Linux version]" | |
dmesg | grep "Linux version" | |
echo | |
echo "[uname -a]" | |
uname -a | |
echo | |
echo "[uptime]" | |
uptime | |
echo | |
echo "[cpuinfo]" | |
cat /proc/cpuinfo | |
echo | |
echo "[meminfo]" | |
cat /proc/meminfo | |
echo | |
echo "[free -m -t]" | |
free -m -t | |
echo | |
echo "[vmstat -n]" | |
vmstat -n | |
echo | |
echo "[df -P -T -m]" | |
df -P -T -m | |
echo | |
echo "[ifconfig]" | |
ifconfig | |
echo | |
echo "[netstat -s]" | |
netstat -s | |
echo | |
echo "[netstat -an]" | |
netstat -an | |
echo | |
echo "[w]" | |
w | |
echo | |
echo "[top -b -n 1]" | |
top -b -n 1 | |
echo | |
echo "[ps -H auxwww]" | |
ps -H auxwww | |
echo | |
echo "[grep SSH attack /var/log/messages]" | |
grep "SSH attack" /var/log/messages | |
echo | |
echo "[grep Fail /var/log/auth.log]" | |
grep "Fail" /var/log/auth.log | |
echo | |
echo -n "End of Report at `/bin/hostname` on " | |
date "+%Y/%m/%d %T" | |
echo |
This file contains 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/sh | |
# /etc/cron.hourly/get_resources | |
JOBLOG=/var/log/resources.log | |
echo -n "*** $0: Job start at `/bin/hostname` on ">>$JOBLOG 2>&1 | |
date "+%Y/%m/%d %T">>$JOBLOG 2>&1 | |
test -x /root/bin/get_resources.sh && /root/bin/get_resources.sh>>$JOBLOG 2>&1; | |
echo -n "*** $0: End of Job at `/bin/hostname` on ">>$JOBLOG 2>&1 | |
date "+%Y/%m/%d %T">>$JOBLOG 2>&1 | |
echo>>$JOBLOG 2>&1 | |
This file contains 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
/var/log/resources.log { | |
daily | |
missingok | |
create 0640 root adm | |
rotate 30 | |
} |
This file contains 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 | |
# script found on <http://d.hatena.ne.jp/Ubuntu/mobile?word=*[resource]> | |
$SCRIPTS=~/Downloads | |
sudo cp $SCRIPTS/get_resources.sh /root/bin/get_resources.sh | |
sudo chmod 700 /root/bin/get_resources.sh | |
sudo chown -R root:root /root/bin | |
sudo cp $SCRIPTS/get_resources /etc/cron.hourly/get_resources | |
sudo chmod 750 /etc/cron.hourly/get_resources | |
sudo chown root:adm /etc/cron.hourly/get_resources | |
sudo touch /var/log/resources.log | |
sudo chmod 640 /var/log/resources.log | |
sudo chown root:adm /var/log/resources.log | |
sudo cp $SCRIPTS/resources-log /etc/logrotate.d/resources | |
sudo chmod 644 /etc/logrotate.d/resources | |
sudo chown root:root /etc/logrotate.d/resources |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment