| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788 |
- #!/bin/bash
- # info: list user log
- # options: user [format]
- #
- # The function of obtaining the list of 100 last users commands.
- #----------------------------------------------------------#
- # Variable&Function #
- #----------------------------------------------------------#
- # Argument defenition
- user=$1
- format=${2-shell}
- # Includes
- source $VESTA/func/main.sh
- # Json func
- json_list_history() {
- echo '{'
- fileds_count=$(echo $fields| wc -w )
- while read line; do
- IFS=$'\n'
- eval $line
- if [ -n "$data" ]; then
- echo -e ' },'
- fi
- i=1
- IFS=' '
- for field in $fields; do
- eval value=\"$field\"
- value=$(echo "$value" | sed -e 's/"/\\"/g' -e "s/%quote%/'/g")
- if [ $i -eq 1 ]; then
- (( ++i))
- echo -e "\t\"$value\": {"
- else
- if [ $i -lt $fileds_count ]; then
- (( ++i))
- echo -e "\t\t\"${field//$/}\": \"${value//,/, }\","
- else
- echo -e "\t\t\"${field//$/}\": \"${value//,/, }\""
- data=1
- fi
- fi
- done
- done < $conf
- if [ -n "$data" ]; then
- echo -e ' }'
- fi
- echo -e '}'
- }
- #----------------------------------------------------------#
- # Verifications #
- #----------------------------------------------------------#
- check_args '1' "$#" 'user [format]'
- validate_format 'user'
- is_object_valid 'user' 'USER' "$user"
- #----------------------------------------------------------#
- # Action #
- #----------------------------------------------------------#
- # Defining config
- conf=$USER_DATA/history.log
- # Defining fileds to select
- fields="\$ID \$DATE \$TIME \$CMD \$UNDO"
- # Listing domains
- case $format in
- json) json_list_history ;;
- plain) nohead=1; shell_list ;;
- shell) fields='$ID~$DATE~$TIME~$CMD';
- shell_list |column -t -s '~';;
- *) check_args '1' '0' 'user [format]'
- esac
- #----------------------------------------------------------#
- # Vesta #
- #----------------------------------------------------------#
- exit
|