The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Help understanding syntax error Issue warlock129 Shell Programming and Scripting 6 04-26-2009 07:02 PM
Annoying tooltips jgrogan Post Here to Contact Site Administrators and Moderators 1 03-10-2009 05:13 PM
Very ANNOYING Problem - Please Help shadow0001 Shell Programming and Scripting 7 03-12-2008 06:28 PM
postfix configuration issues...specifically masquerading (lack of ) mr_manny Linux 5 08-01-2007 10:14 AM
a very annoying problem Stormpie UNIX for Dummies Questions & Answers 2 04-24-2002 12:29 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 05-18-2009
jzacsh jzacsh is offline
Registered User
  
 

Join Date: Apr 2009
Posts: 29
Exclamation lack of understanding > annoying error

I'm working on a script I wrote called backup.sh
when I run it like this:
Code:
. ./backup.sh
I get this error:
Code:
ksh: ./backup.sh[124]: no closing quote
when I run it this way:
Code:
backup.sh
I get this error:
Code:
backup.sh: 28: Syntax error: end of file unexpected (expecting "fi")
I looked through the code over and over (the entire script) and can't find any mismatching quotes or badly nested if statements. I don't have a strong enough understanding to know why one way is better or worse, and why either of them should be handled differently by the shell (I'm guessing they're being handled differently, otherwise they wouldn't have different output, right?)

Any help would be greatly appreciated. In-case this requires a look at the code:
Code:
#!/bin/sh

toBackUpDir="./tmp" #DIRECTORY TO BE BACKED UP
toBackUp="$toBackUpDir/*" #PATH TO BE BACKED UP
landingDir="./download/" #PATH FOR *.TGZ BACKUP TO BE STORED
sql_bDir="./sql_backups/"

#ERROR CHECK, DOES SPECIFIED LANDING DIRECTORY EXIST; ANY OLD BACKUPS?
echo "Checking for specified landing directory: $landingDir"

if [ -d $landingDir ]
then
    echo "Directory $landingDir is present and ready to receive backup."

    echo "Checking that $landingDir does not contain old backup files."
    tarCheck=`ls $landingDir | grep -i *tar*` #CHECKS IF ANY TAR IS SITTING IN DESTINATION FOLDER
    echo "The variable \$tarCheck returns:" $tarCheck #TEST OF VARIABLE

        # ERROR CHECK, ANY PREVIOUS BACKUPS STILL HERE?
        if [ -z $tarCheck ]
        then
            echo "Continuing backup sequence, as there are no old tars in the backup directory $landingDir"
            work="STARTING"
            echo "BEFORE NESTED ELSE"
        else
            echo "I am not ready to backup, first download and delete the above mentioned contents of the $landingDir landing directory." 
            work="NOT starting"
            echo "AFTER NESTED ELSE"
        fi #ENDIF FOR ERROR CHECKING
    echo "AFTER NESTED IF"
else
    echo "Directory $landingDir does not exist, creating it now"
    work="STARTING"
    mkdir $landingDir
fi #ENDIF LANDING DIR. CHECK


# MAIN MODULE: PARAMETERS, ERROR CHECK, TAR, GZIP
if [ $work = "STARTING" ]
then
        #OLD WAY: #fileName=`date | sed -n s/ /_/g p | sed -n s/^/Backup_/p | sed -n s/$/\.tgz/p |  sed -n s/^
/$landingDir/p`  #NAME OF BACKUP FILE
        fileName=`date | sed -n s/ /_/g p`
        fileName=${landingDir}Backup_${fileName}.tgz #NEW WAY #NAME OF BACKUP FILE

        #ERROR CHECK, DOES LOCATION TO BE BACKED UP EXIST?
        echo "The variable \$toBackUpDir (directory of files to be backed up) is: $toBackUpDir"
        echo "Making sure above said target exists: $toBackUpDir"

                if [ -d $toBackUpDir ]
                then
                        echo "Directory $toBackUpDir does indeed exist and is present for backing up."
    
        #CONTINUE PROGRAM

            echo "The variable \$fileName will be:" $fileName
    
        #START SQL BACKUP + TGZ 
            #MYSQL LANDING DIR. CHECK
            echo "Checking if sql backup landing directory exists: $sql_bDir"
            if [ -d $sql_bDir ]
            then
                echo "Database backup directory exists"
            else
                echo "Database backup directory does not exist, creating it"
                mkdir $sql_bDir
            fi #ENDIF SQL DIR. CHECK

            # MYSQL BACKUP
                   sql_bName=`date | sed -n s/ /_/g p | sed -n s/^/SqlBackup_`
            echo "The variable \$sql_bName will be $sql_bName" #TEST OF SQL NAME VARIABLE
            #mysqldump -uxxxxxx -pxxxxxx --opt information_schema > /$sql_bDir/$sql_bName.tgz

            # MYSQL CLEAN-UP < 10 FILES
            # CODE TO CLEAN UP OLDEST OF LISTING (ls -la)
            # THAT AMOUNTS TO GREATER THAN 10 ITEMS

            echo "Below are the files placed in final back up:" #EXPLANATION FOR USER
            tar zcvf "$fileName" $toBackUp #CREATE TGZ
    
            #DECLARE BACKUP FINISHED
            echo " " #VISUAL PADDING
            echo "Final back-up ready for download in, including \"information_schema\" database: $landingDir"

            else
            echo "ERROR:"
            echo "    Directory $toBackUpDir does not exist."
            echo "    Make sure my starting parameters are properly set."
            echo "Backup sequence ended early."
        fi #ENDIF BACKUP DIR. CHECK

fi #ENDIF FOR MAIN MODULE

Last edited by jzacsh; 05-21-2009 at 09:52 AM..
 

Bookmarks

Tags
error, script

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:25 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0