Hey all,
Doing another script and wanted to test it even although I haven't finished it yet. Giving me the error:
Right I understand that its near the ;; at the end of '1') for the case statement, when i take away the esac from the nested case it gives the same error, all that I could think was that it didn't like the nested case. But I'm really unsure whats wrong.
Could someone have a look a a show me where my stupidness is please.
Thanks again
Stephen
Doing another script and wanted to test it even although I haven't finished it yet. Giving me the error:
Code:
work OS.sh: line 180: syntax error near unexpected token `;;'
work OS.sh: line 180: `;;'
Right I understand that its near the ;; at the end of '1') for the case statement, when i take away the esac from the nested case it gives the same error, all that I could think was that it didn't like the nested case. But I'm really unsure whats wrong.
Could someone have a look a a show me where my stupidness is please.
Code:
#!/bin/bash
# Stephen Ross' Backup Script
# Declaring the variables and the path names
BackupWp = /Users/rosstephen/Documents/wp/Archive_$(date '+%d.%m.%y:%H:%M').tgz
BackupSs = /Users/rosstephen/Documents/ss/Archive_$(date '+%d.%m.%y:%H:%M').tgz
BackupPic = /Users/rosstephen/Documents/pics/Archive_$(date '+%d.%m.%y:%H:%M').tgz
Restore = /Users/rosstephen/Documents
# Begin while statement
while true;
do
# User choice menu - Main Menu
clear
echo ****************************************************************
echo Backup and Restore
echo ****************************************************************
echo Please select an option from 1-3:
echo
echo "1) Create a backup"
echo
echo "2) Restore a file from a backup"
echo
echo "3) Exit system"
echo
# Read user input
read USERCHOICE
# Begin the case statement
case $USERCHOICE in
'1') # Begin another while statement
while true;
do
# User choice menu - Backup Menu
clear
echo ******************************************************************
echo Backup
echo ******************************************************************
echo Please select an option 1-4:
echo
echo "a) Backup text document"
echo
echo "b) Backup spreadsheet document"
echo
echo "c) Backup picture"
echo
echo "d) Return to Main Menu"
echo
# Read user input
read USERCHOICE2
# Begin the next case statement
case $USERCHOICE2 in
'a') clear
echo Backup of Text Document
sleep 2
# Ask user for the pathname to the file they want to backup
echo Please enter the complete pathname of the file that you would like to backup.
echo Remember you are in:
pwd
# Read in the filename
read FILETEXT
# If statement to make sure the file is available and is a file not a directory
# Otherwise give an error then ask again for a path
if [ -f "$FILETEXT" ]; then
echo You are going to backup the selected file:
echo "$FILETEXT"
echo The file will be backed up to the "wp" folder
sleep 3
else
echo That is an incorrect path,
echo please check the path and file,
echo then enter the pathname again
read FILETEXT
fi
# Execute the backup with arguments czf
tar -cf $BackupWp $FILETEXT
# If statement to see if the tar statement failed or succeded
# If failed give an error and return to Backup Menu
if [ $? == 0]; then
echo Backup has been successful
sleep 3
else
echo Your backup could not be completed, a problem occured..
sleep 3
fi
;;
'b') clear
echo Backup of Spreadsheet Document
sleep 2
echo Please enter the complete pathname of the file that you would like to backup.
echo Remember you are in:
pwd
read FILESPREAD
if [ -f "$FILESPREAD" ]; then
echo You are going to backup the selected file:
echo "$FILESPREAD"
echo The file will be backed up to the "ss" folder
sleep 3
else
echo That is an incorrect path,
echo please check the path and file,
echo then enter the pathname again
read FILESPREAD
fi
tar -czf $BackupSs $FILESPREAD
if [ $? == 0 ]; then
echo Backup has been successful
sleep 3
else
echo Your backup could not be completed, a problem occured..
sleep 3
fi
;;
'd') clear
echo Backup of Picture
sleep 2
echo Please enter the complete pathname of the file that you would like to backup.
echo Remember you are in:
pwd
read FILEPIC
if [ -f "$FILEPIC" ]; then
echo You are going to backup the selected file:
echo "$FILEPIC"
echo The file will be backed up to the "pics" folder
sleep 3
else
echo That is an incorrect path,
echo please check the path and file,
echo then enter the pathname again
read FILEPIC
fi
tar -czf $BackupPic $FILEPIC
if [ $? == 0]; then
echo Backup has been successful
sleep 3
else
echo Your backup could not be completed, a problem occured..
sleep 3
fi
;;
'c') clear
;;
*) clear
echo Please try again select 1, 2, 3 or 4 only
echo Press enter to continue
read -n 1
;;
;;
'2') clear
echo ******************************************************************
echo Restore
echo ******************************************************************
echo
echo
;;
*)
;;
Thanks again
Stephen