Edit File: timestampchecker.sh
#!/bin/bash # Ask the user if they want to display all results (yes/no) echo "Do you want to display all results? (yes/no)" read display_all # Define color codes RED='\033[0;31m' GREEN='\033[0;32m' NC='\033[0m' # No Color # Navigate to the directory containing the folders cd /usr/local/cpanel/bin/l || exit # Prepare the list of folders sorted by date folders=($(ls -d */ | sort -t'/' -k1.5,1.8n -k1.3,1.4n -k1.1,1.2n)) # Loop through each sorted folder for folder in "${folders[@]}"; do # Ensure we are only dealing with directories if [ -d "$folder" ]; then # Change directory to the folder cd "$folder" # Check if cpanel.lisc exists if [ -f "cpanel.lisc" ]; then # Extract the license expire time from cpanel.lisc license_expire_time=$(grep -a 'license_expire_time:' cpanel.lisc | cut -d ':' -f 2 | tr -d ' ') # Convert the timestamp to human-readable date if [[ -n "$license_expire_time" && "$license_expire_time" -gt 0 ]]; then # Format for folder name as DDMMYYYY folder_date=$(echo ${folder%/} | sed -r 's/(..)(..)(....)/\3-\2-\1/') # Convert license_expire_time to YYYY-MM-DD expiry_date=$(date -d @"$license_expire_time" "+%Y-%m-%d") # Calculate days difference d1=$(date -d "$folder_date" "+%s") d2=$(date -d "$expiry_date" "+%s") diff=$(( (d2 - d1) / 86400 )) # Format output date formatted_date=$(date -d @"$license_expire_time" "+%e %B %Y" | sed 's/^ //') # Check if the difference is within the specified range if [[ $diff -lt 5 || $diff -gt 10 ]]; then echo -e "${RED}${folder%/} $formatted_date - NOT within 5-10 days range (Diff: $diff days)${NC}" elif [[ "$display_all" == "yes" ]]; then echo -e "${GREEN}${folder%/} $formatted_date - Within 5-10 days range (Diff: $diff days)${NC}" fi else echo "${folder%/} No valid expiry time found" fi else echo "${folder%/} cpanel.lisc not found" fi # Navigate back to the main directory cd .. fi done