sorahx0

Untitled

May 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.05 KB | None | 0 0
  1. #!/bin/bash
  2. database="/root/usuarios.db"
  3. echo $$ > /tmp/pids
  4. if [ ! -f "$database" ]
  5. then
  6.     echo "Arquivo /root/usuarios.db não encontrado"
  7.     exit 1
  8. fi
  9. while true
  10. do
  11. tput setaf 7 ; tput setab 4 ; tput bold ; printf '%28s%s%-18s\n' "SSH Limiter"
  12. tput setaf 7 ; tput setab 4 ; printf '  %-30s%s\n' "Usuário" "Conexão/Limite " ; echo "" ; tput sgr0
  13.     while read usline
  14.     do
  15.         user="$(echo $usline | cut -d' ' -f1)"
  16.         s2ssh="$(echo $usline | cut -d' ' -f2)"
  17.         if [ -z "$user" ] ; then
  18.             echo "" > /dev/null
  19.         else
  20.             ps x | grep [[:space:]]$user[[:space:]] | grep -v grep | grep -v pts > /tmp/tmp2
  21.             s1ssh="$(cat /tmp/tmp2 | wc -l)"
  22.             tput setaf 3 ; tput bold ; printf '  %-35s%s\n' $user $s1ssh/$s2ssh; tput sgr0
  23.             if [ "$s1ssh" -gt "$s2ssh" ]; then
  24.                 tput setaf 7 ; tput setab 1 ; tput bold ; echo " Usuário desconectado por ultrapassar o limite!" ; tput sgr0
  25.                 while read line
  26.                 do
  27.                     tmp="$(echo $line | cut -d' ' -f1)"
  28.                     kill $tmp
  29.                 done < /tmp/tmp2
  30.                 rm /tmp/tmp2
  31.             fi
  32.         fi
  33.     done < "$database"
  34.     sleep 5
  35.     clear
  36. done
Add Comment
Please, Sign In to add comment