Skip to main content

Thread: nested if else 'unexpected ";" ? please help.


hi all,

first post. have been reading forum fair while though. , lot of other recently. until have solved problems have had reading out there. 1 can't.

writing script. read users text file , run loop iterate procedure each user.

have added nested if else , getting error @ 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

telling me there unexpected semi colon.

believe may inside condition brackets don't know.

here complete script (not finished now).

code:
#!/bin/bash               #############################################             # 	                                        #	    	 	    # backup /media/external ntfs usb device #	     	    #						#	    	 	    #############################################    # populate user list array text file  	# set field separator value new line  		old_ifs=$ifs 		ifs=$'\n:'  	# create array  		users=($(cat ./userlist.txt)) 			 	# reset ifs default  		ifs=$old_ifs 	 	# print contents of array 		echo 		echo 		echo "initialising" 		echo "please wait" 		echo  		echo  		echo "users backed up: ${users[*]}" 		echo  		echo  		echo "you can add users backup list \ 			 editing userlist.txt"  	# mount directory backup 			  	sudo mount -t ntfs-3g /dev/sdb1 /media/external 		 		echo  		echo 	  	# assign users backup  		################ 		## start loop ## 		################  		for in  ${users[@]}; 			 	# source  	 		backup_source="/home/${i}"  		echo  		echo  		echo " backup source ---------- $backup_source"  	# destination  		dest="/media/external" 	 	# create archive filename  		archive_file="${i}-$(date +%y%m%d).tar.gz" 		date 		echo  	# print start status message.  		echo "backing $backup_source $dest/$archive_file" 		date 		echo 		echo  		echo   	# backup files using tar [and create snapshot file incremental]  		if [[ -f /var/log/snar/${i}5.snar]];  			mv /var/log/snar /var/log/snar/backup 			rm -rf /var/log/snar  		else if [[ -f /var/log/snar/${i}4.snar]]; 				tar -cvw \ 				= $dest/$archive_file $backup_source \ 				--listed-incremental=/var/log/snar/${i}5.snar   		else if [[ -f /var/log/snar/${i}3.snar]];  			tar -cvw \  			= $dest/$archive_file $backup_source \ 			--listed-incremental=/var/log/snar/${i}4.snar  		else if [[ -f /var/log/snar/${i}2.snar]];  			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 check files sizes.  		echo "the following list of files in backup directory..." 		ls -lh $dest 		echo 		echo 		echo  		echo  		echo "today's backup complete" 		echo  		echo 	 		echo "please wait while external media removed" 		echo 		echo  	 	# unmount external drive  	echo "removing external drive mount..." 	sudo umount /media/external

change:
code:
mv /var/log/snar /var/log/snar/backup rm -rf /var/log/snar
to:

code:
mv /var/log/snar /var/log/snar/backup && rm -rf /var/log/snar
makes neater. did error tell line number?


Forum The Ubuntu Forum Community Ubuntu Specialised Support Ubuntu Servers, Cloud and Juju Server Platforms [ubuntu] nested if else 'unexpected ";" ? please help.


Ubuntu

Comments

Popular posts from this blog

Adobe Acrobat Pro , Terminal Server Use

Thread: transmission-daemon isn't playing nice: "409: Conflict"

Thread: gpg: Conflicting Commands