Umpierre

configurando 10 alterar limite

Dec 8th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #!/bin/bash
  2. database="/root/usuarios.db"
  3. tput setaf 7 ; tput setab 4 ; tput bold ; printf '%20s%s\n' " Alterar limite de conexões SSH simultâneas " ; tput sgr0
  4. if [ ! -f "$database" ]
  5. then
  6. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "Arquivo $database não encontrado" ; echo "" ; tput sgr0
  7. exit 1
  8. else
  9. tput setaf 2 ; tput bold ; echo ""; echo "Limite de conexões simultâneas dos usuários:" ; tput sgr0
  10. tput setaf 3 ; tput bold ; echo "" ; cat $database ; echo "" ; tput sgr0
  11. read -p "Nome de usuário para alterar o limite: " usuario
  12. if [[ -z $usuario ]]
  13. then
  14. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "Você digitou um nome de usuário vazio ou não existente na lista!" ; echo "" ; tput sgr0
  15. exit 1
  16. else
  17. if [[ `grep -c "^$usuario " $database` -gt 0 ]]
  18. then
  19. read -p "Número de conexões simultâneas permitidas para o usuário: " sshnum
  20. if [[ -z $sshnum ]]
  21. then
  22. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "Você digitou um número inválido!" ; echo "" ; tput sgr0
  23. exit 1
  24. else
  25. if (echo $sshnum | egrep [^0-9] &> /dev/null)
  26. then
  27. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "Você digitou um número inválido!" ; echo "" ; tput sgr0
  28. exit 1
  29. else
  30. if [[ $sshnum -lt 1 ]]
  31. then
  32. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "Você deve digitar um número de conexões simultâneas maior que zero!" ; echo "" ; tput sgr0
  33. exit 1
  34. else
  35. grep -v ^$usuario[[:space:]] /root/usuarios.db > /tmp/a
  36. sleep 1
  37. mv /tmp/a /root/usuarios.db
  38. echo $usuario $sshnum >> /root/usuarios.db
  39. tput setaf 7 ; tput setab 1 ; tput bold ; echo "" ; echo "O número de conexões simultâneas permitidas para o usuário $usuario foi alterado:" ; tput sgr0
  40. tput setaf 3 ; tput bold ; echo "" ; cat $database ; echo "" ; tput sgr0
  41. exit
  42. fi
  43. fi
  44. fi
  45. else
  46. tput setaf 7 ; tput setab 4 ; tput bold ; echo "" ; echo "O usuário $usuario não foi encontrado na lista!" ; echo "" ; tput sgr0
  47. exit 1
  48. fi
  49. fi
  50. fi
Add Comment
Please, Sign In to add comment