v-list-sys-users 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #!/bin/bash
  2. # info: list system users
  3. # options: [FORMAT]
  4. #
  5. # The function for obtaining the list of system users without
  6. # detailed information.
  7. #----------------------------------------------------------#
  8. # Variable&Function #
  9. #----------------------------------------------------------#
  10. # Argument definition
  11. format=${1-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # JSON list function
  15. json_list() {
  16. objects=$(grep @ /etc/passwd |wc -l)
  17. i=1
  18. echo '['
  19. while read user; do
  20. if [ "$i" -lt "$objects" ]; then
  21. echo -e "\t\"$user\","
  22. else
  23. echo -e "\t\"$user\""
  24. fi
  25. (( ++i))
  26. done < <(grep @ /etc/passwd |cut -f 1 -d :)
  27. echo "]"
  28. }
  29. # SHELL list function
  30. shell_list() {
  31. echo "USER"
  32. echo "----"
  33. while read user; do
  34. echo "$user"
  35. done < <(grep @ /etc/passwd |cut -f 1 -d :)
  36. }
  37. # PLAIN list function
  38. plain_list() {
  39. while read user; do
  40. echo "$user"
  41. done < <(grep @ /etc/passwd |cut -f 1 -d :)
  42. }
  43. # CSV list function
  44. csv_list() {
  45. echo "USER"
  46. while read user; do
  47. echo "$user"
  48. done < <(grep @ /etc/passwd |cut -f 1 -d :)
  49. }
  50. #----------------------------------------------------------#
  51. # Action #
  52. #----------------------------------------------------------#
  53. # Listing data
  54. case $format in
  55. json) json_list ;;
  56. plain) plain_list ;;
  57. csv) csv_list ;;
  58. shell) shell_list ;;
  59. esac
  60. #----------------------------------------------------------#
  61. # Vesta #
  62. #----------------------------------------------------------#
  63. exit