I'm using this bash script to maintain 3 backups of my server. For some reason, it randomly creates an empty file with the name of one of my variables. The variable name it chooses is seemingly random, and it doesn't create the file every single time that it's run.
I'm running Ubuntu Server 16.04LTS
The script works perfectly as intended. I'm just wondering why bash creates the file sometimes.
NOTE: I have omitted some sensitive information such as the Samba address, and location of the CIFS credentials. This was intentional and is correct in my actual script.
I'm running this script from a cron job with the command
bash backup.bash, so bash is explicitly used to run the script
#!/bin/bash ## The number of backups that we want to keep MAX_BACKUPS=3 ## The directory to store the backups BACKUP_DIR="OMITTED" ## The address of the Samba Share REMOTE_ADDR="OMITTED" ## What we want to name the backup BACKUP_NAME="$(date +"%m_%d_%Y")_backup.tar.gz" ## Mount the Samba Share to the backup directory mount -t cifs -o credentials=OMITTED,noperm $REMOTE_ADDR $BACKUP_DIR ## Make todays backup tar -cpzvf $BACKUP_DIR/$BACKUP_NAME --exclude-from=/backup_scripts/backup.exclude / ## The number of backups that we now have COUNT="$(find $BACKUP_DIR -maxdepth 1 -type f -name '*_backup.tar.gz' | wc -l )" ## If we have more backups than MAX_BACKUPS if ((COUNT > MAX_BACKUPS)); then ## Delete the oldest file (DETERMINED BY MODIFICATION DATE) cd $BACKUP_DIR rm "$(ls -t | tail -1)" fi # Unmount the Samba Share for safety umount $BACKUP_DIR