LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problems running batch file (https://www.linuxquestions.org/questions/linux-newbie-8/problems-running-batch-file-697533/)

Poison Ivy 30 01-15-2009 11:04 AM

Problems running batch file
 
No matter what I do, it keeps coming up with errors, whenever I think I have fixed the error it seems to come up with something else and for some reason I cant see what I have done wrong. Error messages occur with fi, then, else.

Here is my script

#!/bin/bash -x
# Creating location of where Lorna Kennedy's backup file will be found #
Backup_Destination=LKBackup/Archive_$(date '+%d.%m.%y:%H:%M').tgz
Restore=LKBackup/

#Begin the while statement

while :
do

#User Menu selection

echo "**********************************************************************"
echo "*********** Backup and Restore ******************************"
echo "********************************************************************"
echo "*********** Chose from Option 1, 2 or 3 ******************"
echo "*******************************************************************"
echo "[1] Create a Backup File"
echo
echo "[2] Restore files and folders from a Backup"
echo
echo "[3] Exit System"
echo
echo
echo "----------- Enter your option [1-3]: ---------------------------"
echo
echo "==================================================================="
# Read Option which User has chosen
read Selection
read Selection

# Begin the case statement
case $Selection in
1) echo "Your selected Perform a Full Backup.";
# pause for 2 seconds
sleep 2
echo "Please enter carefully, the path of the files to backup";
# Read Option which User has chosen and error correct path and on
execution if it returns 0 then it is successful
read LOCATION
if [-d "$LOCATION"]; then
echo you are going to backup the files within "$LOCATION";
echo "the files or folders will be backed up to the location";
echo "folder named LKBackups";
# pause for 2 seconds
sleep 2

else
echo "error the file path is not valid or the files do not exist";
echo "please ensure that the file path entered is correct";
echo "please enter the file path or name again";
read LOCATION

# Execute backup of files
tar -cf $Backup_Destination $LOCATION

fi
# Check to make sure that the backup has completed correctly

if [$? == 0]; then
echo "$Backup_Destination" has been successful.;
# pause for 3 seconds
sleep 3

else

echo "There was an error with the files or folders so backup could not be
completed.";
# pause for 3 seconds
sleep 3

fi

;;

2) echo "You are about to restore files or folders from a backup":
# pause for 3 seconds
sleep 3

echo "any backups that are held within the backup folder will be listed
below";

ls "$Restore"
echo "select the file that you would like restored";
echo "enter the full path name carefully";
read RESTOREBACKUP
Restore_Destination="$Restore_Destination""$RESTOREBACKUP"
if [-f"$Restore_Destination"];
echo "Your files selected will now be restored";
# pause for 4 seconds
sleep 4
else

echo "There was an error with the file name";
echo "Please re-enter the file name";
read RESTOREBACKUP
Restore_Destination="$Restore_Destination""$RESTOREBACKUP"
fi

echo "The selected files will now be restored";
# pause for 4 seconds
sleep 4
tar -xf $Restore_Destination

if[$? == 0]; then
echo "$RESTOREBACKUP" backup has been successful;
# pause for 4 seconds
sleep 4

else

echo "There was a problem with your restore";
echo "Please check your file name is correct";

fi
;;

3) echo "GoodBye see you again soon $USER";
exit 1
;;

*) echo "Sorry you can only select from options 1, 2 or 3. Please try
again";
echo "press any key to continue";
read -n 1
;;
esac
done


I have no idea why it wont run properly, can anyone help please

dracofhc 01-15-2009 01:15 PM

Could you please post any relevant error message.

(fyi batch files are the ms-dos equivalent, we call them scripts)

Poison Ivy 30 01-15-2009 01:42 PM

./backup.sh: line 94: syntax error near unexpected token `else'
./backup.sh: line 94: `else'


Sorry, I should have said script. Excuse me, Im new to this

vasmakk 01-16-2009 02:23 AM

Quote:

Originally Posted by Poison Ivy 30 (Post 3410144)
./backup.sh: line 94: syntax error near unexpected token `else'
./backup.sh: line 94: `else'


Sorry, I should have said script. Excuse me, Im new to this

I'm not sure, but as I see through the code, try change line 94
if [-f"$Restore_Destination"];

to
if [-f"$Restore_Destination"]; then

like the previous ones ? Maybe this do the work ...
Let me know

Vas


All times are GMT -5. The time now is 09:05 PM.