v-list-user-log 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #!/bin/bash
  2. # info: list user log
  3. # options: user [format]
  4. #
  5. # The function of obtaining the list of 100 last users commands.
  6. #----------------------------------------------------------#
  7. # Variable&Function #
  8. #----------------------------------------------------------#
  9. # Argument defenition
  10. user=$1
  11. format=${2-shell}
  12. # Includes
  13. source $VESTA/func/main.sh
  14. # Json func
  15. json_list_history() {
  16. echo '{'
  17. fileds_count=$(echo $fields| wc -w )
  18. while read line; do
  19. IFS=$'\n'
  20. eval $line
  21. if [ -n "$data" ]; then
  22. echo -e ' },'
  23. fi
  24. i=1
  25. IFS=' '
  26. for field in $fields; do
  27. eval value=\"$field\"
  28. value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
  29. if [ $i -eq 1 ]; then
  30. (( ++i))
  31. echo -e "\t\"$value\": {"
  32. else
  33. if [ $i -lt $fileds_count ]; then
  34. (( ++i))
  35. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
  36. else
  37. echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
  38. data=1
  39. fi
  40. fi
  41. done
  42. done < $conf
  43. if [ -n "$data" ]; then
  44. echo -e ' }'
  45. fi
  46. echo -e '}'
  47. }
  48. #----------------------------------------------------------#
  49. # Verifications #
  50. #----------------------------------------------------------#
  51. check_args '1' "$#" 'user [format]'
  52. validate_format 'user'
  53. is_object_valid 'user' 'USER' "$user"
  54. #----------------------------------------------------------#
  55. # Action #
  56. #----------------------------------------------------------#
  57. # Defining config
  58. conf=$USER_DATA/history.log
  59. # Defining fileds to select
  60. fields="\$ID \$DATE \$TIME \$CMD \$UNDO"
  61. # Listing domains
  62. case $format in
  63. json) json_list_history ;;
  64. plain) nohead=1; shell_list ;;
  65. shell) fields='$ID~$DATE~$TIME~$CMD';
  66. shell_list |column -t -s '~';;
  67. *) check_args '1' '0' 'user [format]'
  68. esac
  69. #----------------------------------------------------------#
  70. # Vesta #
  71. #----------------------------------------------------------#
  72. exit