Skip to content

Instantly share code, notes, and snippets.

@bouroo
Created December 22, 2024 06:43
Reset Plesk traffic for both incoming and outgoing HTTP traffic for specific domain.
#!/usr/bin/env bash
# Prompt user to enter the domain
read -p "Please enter the domain (e.g., example.com): " domain
# Get the current year and month
current_year=$(date +%Y)
current_month=$(date +%m)
# Get the first day of the current month
first_day_of_month="${current_year}-${current_month}-01"
# Get the current date
current_date=$(date +%Y-%m-%d)
# Loop from the first day of the month to the current date
current_day=$(date -d "$first_day_of_month" +%s)
end_day=$(date -d "$current_date" +%s)
while [ $current_day -le $end_day ]; do
# Format the current date in YYYY-MM-DD
formatted_date=$(date -d @$current_day +%Y-%m-%d)
# Reset traffic for the specified domain and date
echo "Resetting traffic for $domain on $formatted_date..."
plesk bin traffic -d "$domain" -date "$formatted_date" -type http -direction out
plesk bin traffic -d "$domain" -date "$formatted_date" -type http -direction in
# Increment the day by one
current_day=$(($current_day + 86400)) # 86400 seconds in a day
done
echo "Traffic reset completed for $domain from $first_day_of_month to $current_date."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment