v-list-sys-users 1.7 KB

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