v_list_sys_users 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/bin/bash
  2. # info: list system users
  3. # options: [format]
  4. #
  5. # The function for obtaining the list of system users.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. format=${1-shell}
  11. # Includes
  12. source $VESTA/func/main.sh
  13. # Json function
  14. json_list_users() {
  15. users=$(grep @ /etc/passwd|cut -f 1 -d :)
  16. int_counter=$(echo "$users" | wc -l)
  17. i=1
  18. echo '['
  19. for user in $users; do
  20. if [ "$i" -lt "$int_counter" ]; then
  21. echo -e "\t\"$user\","
  22. else
  23. echo -e "\t\"$user\""
  24. fi
  25. (( ++i))
  26. done
  27. echo "]"
  28. }
  29. # Shell function
  30. shell_list_users() {
  31. if [ -z "$nohead" ]; then
  32. echo "USERS"
  33. echo "----------"
  34. fi
  35. for user in $(grep @ /etc/passwd|cut -f 1 -d :); do
  36. echo "$user"
  37. done
  38. }
  39. #----------------------------------------------------------#
  40. # Action #
  41. #----------------------------------------------------------#
  42. # Listing domains
  43. case $format in
  44. json) json_list_users ;;
  45. plain) nohead=1; shell_list_users ;;
  46. shell) shell_list_users ;;
  47. *) check_args '1' '0' '[format]' ;;
  48. esac
  49. #----------------------------------------------------------#
  50. # Vesta #
  51. #----------------------------------------------------------#
  52. exit