System monitor

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
Last modified
Lines 44
Indexable No

Parent directory Download CGIread sitemap Main page

Quick links: (none)

  1. #!/bin/sh
  2. touch tmp.monitor
  3. chmod 0600 tmp.monitor || exit
  4. while :
  5. do
  6.     clear
  7.     cat tmp.monitor
  8.     
  9.     echo "    **Procs**" > tmp.monitor
  10.     top -bn1 | grep -E '(ssh(oskar|guest)|www-data|agnes|COMMAND)' >> tmp.monitor
  11.     N_PROCS=5
  12.     top -bn1 | head -n $(($N_PROCS + 7)) | tail -n $(($N_PROCS)) >> tmp.monitor
  13.     
  14.     echo '    **who**' >> tmp.monitor
  15.     who | grep -vE '^oskar +(:0|tty[0-9])|^guest +tty[0-9]' >> tmp.monitor
  16.     
  17.     echo '    **uptime**' >> tmp.monitor
  18.     uptime >> tmp.monitor
  19.     
  20.     echo '    **Fail2ban**' >> tmp.monitor
  21.     today=`date +%Y-%m-%d`
  22.     lines=5
  23.     f="/var/log/fail2ban.log"
  24.     echo Unban `grep $today $f | grep Unban | cut -d' ' -f7 | wc -l` >> tmp.monitor
  25.     grep $today $f | grep Unban | cut -d' ' -f2,5,7 | tail -n $lines >> tmp.monitor
  26.     echo Ban `grep $today $f | grep Ban | cut -d' ' -f7 | wc -l` >> tmp.monitor
  27.     grep $today $f | grep Ban | cut -d' ' -f2,5,7 | tail -n $lines >> tmp.monitor
  28.     
  29.     echo '    **SSH**' >> tmp.monitor
  30.     netstat --inet -W -n  | grep -E '62\.72\.235\.216:22(22)? +[0-9]' | grep ESTABLISHED >> tmp.monitor
  31.     
  32.     echo '    **free**' >> tmp.monitor
  33.     free -m >> tmp.monitor
  34.     
  35.     echo '    **Temp**' >> tmp.monitor
  36.     sensors coretemp-isa-0000 | grep '°C' >> tmp.monitor
  37.     
  38.     echo '    **Disk space**' >> tmp.monitor
  39.     df -H | grep -vE ' /(run|dev|sys)(/.*)?' >> tmp.monitor
  40.     
  41.     sleep 5
  42. done