Hi all,
My first post. I have been reading this forum for a fair while though. And a lot of other recently. Up until now I have solved all the problems I have had by reading what is out there. This one I can't.
I am writing a back up script. I read the users from a text file and then run a loop to iterate the back up procedure for each user.
I have just now added a nested if else and I am getting an error at the first line listed below,
if [[ -f /var/log/snar/${i}5.snar]]; then
mv /var/log/snar /var/log/snar/backup
rm -rf /var/log/snar
It is telling me there is an unexpected semi colon.
I believe it may be something inside the condition brackets but I don't know.
Here is the complete script (not finished but as it is now).
Code:#!/bin/bash ############################################# # # # Backup to /media/external NTFS USB device # # # ############################################# # Populate User list array from text file # Set field separator value to new line old_IFS=$IFS IFS=$'\n:' # Create array users=($(cat ./userlist.txt)) # Reset IFS to default IFS=$old_IFS # Print Contents of Array echo echo echo "Initialising" echo "Please Wait" echo echo echo "Users to be backed up: ${users[*]}" echo echo echo "You can add users to the backup list \ by editing userlist.txt" # Mount directory for backup sudo mount -t ntfs-3g /dev/sdb1 /media/external echo echo # Assign users for backup ################ ## START LOOP ## ################ for i in ${users[@]}; do # Back up source BACKUP_SOURCE="/home/${i}" echo echo echo " BACKUP SOURCE IS ---------- $BACKUP_SOURCE" # Back up destination DEST="/media/external" # Create archive filename ARCHIVE_FILE="${i}-$(date +%Y%m%d).tar.gz" date echo # Print start status message. echo "Backing up $BACKUP_SOURCE to $DEST/$ARCHIVE_FILE" date echo echo echo # Backup the files using tar [And create snapshot file for incremental] if [[ -f /var/log/snar/${i}5.snar]]; then mv /var/log/snar /var/log/snar/backup rm -rf /var/log/snar else if [[ -f /var/log/snar/${i}4.snar]]; then tar -cvW \ = $DEST/$ARCHIVE_FILE $BACKUP_SOURCE \ --listed-incremental=/var/log/snar/${i}5.snar else if [[ -f /var/log/snar/${i}3.snar]]; then tar -cvW \ = $DEST/$ARCHIVE_FILE $BACKUP_SOURCE \ --listed-incremental=/var/log/snar/${i}4.snar else if [[ -f /var/log/snar/${i}2.snar]]; then tar -cvW \ = $DEST/$ARCHIVE_FILE $BACKUP_SOURCE \ --listed-incremental=/var/log/snar/${i}3.snar else tar -cvW \ = $DEST/$ARCHIVE_FILE $BACKUP_SOURCE \ --listed-incremental=/var/log/snar/${i}.snar fi fi # Print end status message. echo echo "Backup of ${i} Complete" date echo echo # End Loop done # Long listing of files in $dest to check files sizes. echo "The following is a list of files in your backup directory..." ls -lh $DEST echo echo echo echo echo "Today's Backup is Complete" echo echo echo "Please wait while External Media is removed" echo echo # Unmount external drive echo "Removing external drive from mount..." sudo umount /media/external
Bookmarks