v_list_sys_users 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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 defenition
  11. format=${1-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # Json function
  15. json_list_users() {
  16. users=$(grep @ /etc/passwd|cut -f 1 -d :)
  17. int_counter=$(echo "$users" | wc -l)
  18. i=1
  19. echo '['
  20. for user in $users; do
  21. if [ "$i" -lt "$int_counter" ]; then
  22. echo -e "\t\"$user\","
  23. else
  24. echo -e "\t\"$user\""
  25. fi
  26. (( ++i))
  27. done
  28. echo "]"
  29. }
  30. # Shell function
  31. shell_list_users() {
  32. if [ -z "$nohead" ]; then
  33. echo "USERS"
  34. echo "----------"
  35. fi
  36. for user in $(grep @ /etc/passwd|cut -f 1 -d :); do
  37. echo "$user"
  38. done
  39. }
  40. #----------------------------------------------------------#
  41. # Action #
  42. #----------------------------------------------------------#
  43. # Listing domains
  44. case $format in
  45. json) json_list_users ;;
  46. plain) nohead=1; shell_list_users ;;
  47. shell) shell_list_users ;;
  48. *) check_args '1' '0' '[format]' ;;
  49. esac
  50. #----------------------------------------------------------#
  51. # Vesta #
  52. #----------------------------------------------------------#
  53. exit