Extract traffic data

This commit is contained in:
Whispering Wind
2024-08-10 12:31:44 +03:30
committed by GitHub
parent aaf31a79f2
commit 438307e908

View File

@ -2,8 +2,6 @@
source /etc/hysteria/core/scripts/path.sh
# Check if a username is provided
if [ -z "$1" ]; then
echo "Usage: $0 <username>"
exit 1
@ -11,22 +9,33 @@ fi
USERNAME=$1
# Check if users.json file exists
if [ ! -f "$USERS_FILE" ]; then
echo "users.json file not found!"
exit 1
fi
# Extract user info using jq
if [ ! -f "$TRAFFIC_FILE" ]; then
echo "traffic_data.json file not found!"
exit 1
fi
USER_INFO=$(jq -r --arg username "$USERNAME" '.[$username] // empty' $USERS_FILE)
# Check if user info is found
if [ -z "$USER_INFO" ]; then
echo "User '$USERNAME' not found."
exit 1
fi
# Print user info
TRAFFIC_INFO=$(jq -r --arg username "$USERNAME" '.[$username] // empty' $TRAFFIC_FILE)
echo "User Information:"
echo "$USER_INFO" | jq .
echo "Traffic Information:"
if [ -z "$TRAFFIC_INFO" ]; then
echo "No traffic data found for user '$USERNAME'."
else
echo "$TRAFFIC_INFO" | jq .
fi
exit 0