For each user, it checks if a backup file exists for the user by running the ls command on the backup path and grepping for the user’s filename with the .tar.gz extension. If the backup file exists, the script prints “Backup available for [user]”. If the backup file does not exist, the script prints “Backup not available for [user]”. The script is very easy to understand.
Note: This script assumes that the user’s backup file is named [username].tar.gz and is located in a directory structure that matches the backup path specified. If the backup file names or directory structure are different, the script will need to be modified accordingly.
#!/bin/bash # Path to check for backups backup_path="/backup/*/*/accounts/*.tar.gz" for user in `ls -A /var/cpanel/users` ; do # Check if backup file exists for user if ls $backup_path 2>/dev/null | grep -q "/$user.tar.gz$"; then echo "Backup available for $user" else echo "Backup not available for $user" fi done