bashI have write simple bash script that checks the availability of Cpanel backups for each user account listed in /var/cpanel/users. The script first sets the backup path to /backup/*/*/accounts/*.tar.gz. This path includes the * wildcard to match any subdirectory names for the first two levels of directories. This allows the script to check backups in multiple directories within /backup.

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.

# Path to check for backups

for user in `ls -A /var/cpanel/users` ;
# 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"
     echo "Backup not available for $user"


Leave a Reply

Your email address will not be published. Required fields are marked *