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 67

Parent directory Download CGIread sitemap Main page

Quick links: (none)

  1. #!/bin/sh
  2. cat > /dev/null << __EOF__
  3. <description>
  4. Keep an eye of:
  5. *processes ran by "remote" users,
  6. *temperature and load average,
  7. *free memory and
  8. *SSH break-in attempts
  9. </description>
  10. <long-description>
  11.     <p>This is a simple system monitor that checks various things</p>
  12.     <ul>
  13.         <li>Logged in users that aren't normally logged in</li>
  14.         <li>Processes ran by remote/compromisable users</li>
  15.         <li>Top five processes from <code>top(1)</code></li>
  16.         <li>Memory, CPU and disk usage</li>
  17.         <li>Temperature</li>
  18.         <li>Fail2ban and current connections to my SSH ports</li>
  19.     </ul>
  20. </long-description>
  21. __EOF__
  22. touch tmp.monitor
  23. chmod 0600 tmp.monitor || exit
  24. while :
  25. do
  26.     clear
  27.     cat tmp.monitor
  28.     
  29.     echo "    **Procs**" > tmp.monitor
  30.     top -bn1 | grep -E '(sshguest|www-data|agnes|COMMAND)' >> tmp.monitor
  31.     N_PROCS=5
  32.     top -bn1 | head -n $(($N_PROCS + 7)) | tail -n $(($N_PROCS)) >> tmp.monitor
  33.     
  34.     echo '    **who**' >> tmp.monitor
  35.     #who | grep -vE '^oskar +(:0|tty[0-9])|^guest +tty[0-9]' >> tmp.monitor
  36.     who >>tmp.monitor
  37.     
  38.     echo '    **uptime**' >> tmp.monitor
  39.     uptime >> tmp.monitor
  40.     
  41.     echo '    **Fail2ban**' >> tmp.monitor
  42.     today=`date +%Y-%m-%d`
  43.     lines=5
  44.     f="/var/log/fail2ban.log"
  45.     echo Unban $(grep $today $f | grep Unban | wc -l) >> tmp.monitor
  46.     grep $today $f | grep Unban | tail -n $lines >> tmp.monitor
  47.     echo Ban $(grep $today $f | grep Ban | wc -l) >> tmp.monitor
  48.     grep $today $f | grep Ban | tail -n $lines >> tmp.monitor
  49.     
  50.     echo '    **SSH**' >> tmp.monitor
  51.     # 62.72.235.216
  52.     netstat --inet -W -n  | grep -E '83\.245\.206\.247:22(22)? +[0-9]' | grep ESTABLISHED >> tmp.monitor
  53.     
  54.     echo '    **free**' >> tmp.monitor
  55.     free -m >> tmp.monitor
  56.     
  57.     echo '    **Temp**' >> tmp.monitor
  58.     sensors coretemp-isa-0000 | grep '°C' >> tmp.monitor
  59.     
  60.     echo '    **Disk space**' >> tmp.monitor
  61.     df -H | grep -vE ' /(run|dev|sys)(/.*)?' >> tmp.monitor
  62.     
  63.     sleep 5
  64. done