LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-15-2009, 12:04 PM   #1
Poison Ivy 30
LQ Newbie
 
Registered: Jan 2009
Posts: 2

Rep: Reputation: 0
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
 
Old 01-15-2009, 02:15 PM   #2
dracofhc
Member
 
Registered: Dec 2005
Location: Kalamazoo, MI, US
Distribution: Gentoo
Posts: 44

Rep: Reputation: 16
Could you please post any relevant error message.

(fyi batch files are the ms-dos equivalent, we call them scripts)
 
Old 01-15-2009, 02:42 PM   #3
Poison Ivy 30
LQ Newbie
 
Registered: Jan 2009
Posts: 2

Original Poster
Rep: Reputation: 0
./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
 
Old 01-16-2009, 03:23 AM   #4
vasmakk
Member
 
Registered: Jan 2009
Distribution: Debian Lenny, Ubuntu 9.04
Posts: 87

Rep: Reputation: 16
Quote:
Originally Posted by Poison Ivy 30 View Post
./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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
batch file for accessing a shared file in ubuntu samba pdelcast Linux - Networking 5 04-24-2008 01:21 AM
Running Windows batch script from Unix rrguyyala AIX 4 08-26-2007 09:43 AM
How to convert a batch file(.bat) to script file(.sh) manas_sem Programming 4 06-28-2007 01:10 PM
Running a DOS batch file nyghtraven Linux - General 4 02-03-2007 03:18 AM
running ssh connection into batch file jdonaldogg General 1 12-17-2005 11:25 PM


All times are GMT -5. The time now is 06:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration