v_list_user_log 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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="\$DATE\$TIME \$CMD \$A1 \$A2 \$A3 \$A4 \$A5 \$A6 \$A7 \$A8 \$A9"
  61. fields="$fields \$TIME \$DATE"
  62. # Listing domains
  63. case $format in
  64. json) json_list_history ;;
  65. plain) nohead=1; shell_list ;;
  66. shell) fields="\$DATE \$TIME \$CMD \$A1 \$A2 \$A3 \$A4 \$A5 \$A6 \$A7"
  67. shell_list ;;
  68. *) check_args '1' '0' 'user [format]'
  69. esac
  70. #----------------------------------------------------------#
  71. # Vesta #
  72. #----------------------------------------------------------#
  73. exit