This is a simple system monitor that checks various things
- Logged in users that aren't normally logged in
- Processes ran by remote/compromisable users
- Top five processes from
top(1)
- Memory, CPU and disk usage
- Temperature
- Fail2ban and current connections to my SSH ports
__EOF__
touch tmp.monitor
chmod 0600 tmp.monitor || exit
while :
do
clear
cat tmp.monitor
echo " **Procs**" > tmp.monitor
top -bn1 | grep -E '(sshguest|www-data|agnes|COMMAND)' >> tmp.monitor
N_PROCS=5
top -bn1 | head -n $(($N_PROCS + 7)) | tail -n $(($N_PROCS)) >> tmp.monitor
echo ' **who**' >> tmp.monitor
#who | grep -vE '^oskar +(:0|tty[0-9])|^guest +tty[0-9]' >> tmp.monitor
who >>tmp.monitor
echo ' **uptime**' >> tmp.monitor
uptime >> tmp.monitor
echo ' **Fail2ban**' >> tmp.monitor
today=`date +%Y-%m-%d`
lines=5
f="/var/log/fail2ban.log"
echo Unban $(grep $today $f | grep Unban | wc -l) >> tmp.monitor
grep $today $f | grep Unban | tail -n $lines >> tmp.monitor
echo Ban $(grep $today $f | grep Ban | wc -l) >> tmp.monitor
grep $today $f | grep Ban | tail -n $lines >> tmp.monitor
echo ' **SSH**' >> tmp.monitor
# 62.72.235.216
netstat --inet -W -n | grep -E '83\.245\.206\.247:22(22)? +[0-9]' | grep ESTABLISHED >> tmp.monitor
echo ' **free**' >> tmp.monitor
free -m >> tmp.monitor
echo ' **Temp**' >> tmp.monitor
sensors coretemp-isa-0000 | grep '°C' >> tmp.monitor
echo ' **Disk space**' >> tmp.monitor
df -H | grep -vE ' /(run|dev|sys)(/.*)?' >> tmp.monitor
sleep 5
done