sergio_educacionit

delet_special_users.sh

Jun 1st, 2026
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3.  
  4.  
  5.  
  6. while read linea; do
  7. # entra la linea entera
  8. # al indice pese a los espacios
  9. arr[$indice]=$linea
  10. ((indice++))
  11.  
  12. done < /etc/passwd
  13.  
  14. # llamar al array con comillas
  15. # aplica a cada cadena de cada incide
  16.  
  17. for user in "${arr[@]}"; do
  18.  
  19. usuario=$(echo $user | cut -d ":" -f1)
  20. id=$(echo $user | cut -d ":" -f 3)
  21. shell=$(echo $user | cut -d ":" -f 7)
  22.  
  23. if [ $id -ge 1 ] && [ $id -le 999 ];then
  24.  
  25. if grep -w $shell /etc/shells;then
  26.  
  27. echo -e "\033[1;31mWARNING\033[0m: special user has shell"
  28. echo "archivos abiertos por $usuario (lsof -u $id)"
  29. lsof -u $id
  30. echo "elimando procesos a nombre de $usuario (pkill -U $id)"
  31. pkill -U $id
  32. echo "eliminar usuario"
  33. userdel -f $usuario
  34.  
  35. fi
  36.  
  37. fi
  38.  
  39.  
  40. done
  41.  
Advertisement
Add Comment
Please, Sign In to add comment