Я совершенно не понимаю, почему эта ошибка продолжает возникать, я вполне уверен, что использую правильный синтаксис, однако каждый раз, когда я выполняю этот сценарий BASH, я получаю следующую ошибку:

/home/clucky/MCServerBackup/MCServerBackup.sh: line 200: syntax error near unexpected token `'2''
/home/clucky/MCServerBackup/MCServerBackup.sh: line 200: `    logInfo() '2' "none" "Minecraft: $minecraftsize.$minecraftsized $minecraftunit"'

В частности, это строка 200, в которой код пытается выполнить функцию logInfo() следующим образом:

logInfo() '2' "none" "Minecraft: $minecraftsize.$minecraftsized $minecraftunit"

В приведенной выше строке кода 2 - это уровень отступа (2 x 5 пробелов). none указывает функции игнорировать logLevel, указанный в конфигурации, и в любом случае регистрировать его. Minecraft: $minecraftsize...$minecraftunit - это то, что добавляется в файл журнала, слова, которым предшествует $, конечно же, переменные. Полный код можно посмотреть ниже.

#! /usr/bin/env bash
#Declare Functions
logInfo() {
if [ "$logInFile" == "true" ] || [ "$logInConsole" == "true" ] ; then
    let tabAmount=5*$1
    indent=""
    for (( indentrepeat=0; indentrepeat < $tabAmount; indentrepeat++ ))
    do
        indent="$indent "
    done
    if [ "$2" == "none" ] ; then

        infoItem="$3"
    else
        if [ "$logLevel" == "high" ] ; then
            if [ "$2" == "subtask" ] ; then
                #High + Subtask
                infoItem="`date '+%H:%M:%S'` $3"
            elif [ "$2" == "task" ] ; then
                #High + Task
                infoItem="`date '+%H:%M:%S'` $3"
            fi
        elif [ "$logLevel" == "medium" ] ; then
            if [ "$2" == "subtask" ] ; then
                #Medium + Subtask
                infoItem="$3"
            elif [ "$2" == "task" ] ; then
                #Medium + Task
                infoItem="`date '+%H:%M:%S'` $3"
            fi
        else
            if [ "$2" == "subtask" ] ; then
                #Low + Subtask
                infoItem=''
            elif [ "$2" == "task" ] ; then
                #Low + Task
                infoItem="$3"
            fi
        fi
    fi
    if [ "$logInFile" == "true" ] ; then
        echo -e "$indent$infoItem" >> backup.log
    fi
    if [ "$logInConsole" == "true" ] ; then
        echo -e "$indent$infoItem"
    fi
fi
}
logError() {
if [ "$logInFile" == "true" ] || [ "$logInConsole" == "true" ] ; then
    let tabAmount=5*$1
    indent=""
    for (( indentrepeat=0; indentrepeat < $tabAmount; indentrepeat++ ))
    do
        indent="$indent "
    done
    if [ "$logInFile" == "true" ] && [ "$logErrors" == "true" ] ; then
        echo -e "$indent[ERROR] $2" >> backup.log
    fi
    if [ "$logInConsole" == "true" ] && [ "$logErrors" == "true" ] ; then
        echo -e "$indent[ERROR] $2"
    fi
fi
}
#Set Variables
source config.sh
minecraftsize=0
sqlsize=0
websitesize=0
timedate=`date '+%m.%d.%Y-%H:%M'`
#Update
if [ $version != "1.0.0" ] ; then
    source update.sh
fi
#Trigger General Settings
echo -ne "\033]0;$serverName - Backup\007"
if [ "$serverDirectory" == "default" ] ; then
    BINDIR="$(dirname "$(readlink -fn "$0")")"
    cd "$BINDIR"
else
    if [ -d "$serverDirectory" ] ; then
        cd "$serverDirectory"
    else
        directoryExists=false
        echo '$serverDirectory defined as '"$serverDirectory"' does not exist. Please double check your configuration and make sure this folder exists.'
        if [ "$logInFile" == "true" ] ; then
            echo "-------------- `date '+%d-%B-%Y %H:%M'` --------------" >> backup.log
            echo -e '     [ERROR] $serverDirectory defined as '"$serverDirectory"', does not exist. Please double check your configuration and make sure this folder exists.'"\n" >> backup.log
        fi
    fi
fi
if [ "$purgeFiles" == "true" ] || [ "$backupMinecraft" == "true" ] || [ "$backupMySQL" == "true" ] || [ "$backupWebsite" == "true" ] && [ "$directoryExists" != "false" ] ; then
    echo "-------------- `date '+%d-%B-%Y %H:%M'` --------------" >> backup.log
    #Create Directories
    echo "[`date '+%H:%M:%S'`] Directory Creation Started" >> backup.log
    if [ ! -d ".backups" ] ; then
        mkdir -p .backups
    fi
    mkdir -p .backups/$timedate
    if [ "$backupMySQL" == "true" ] ; then
        mkdir -p .backups/$timedate/MySQL
    fi
    if [ "$backupWebsite" == "true" ] ; then
        mkdir -p .backups/$timedate/Website
    fi
    if [ "$backupMinecraft" == "true" ] ; then
        mkdir -p .backups/$timedate/MinecraftServers
    fi
    echo "[`date '+%H:%M:%S'`] Directory Creation Completed" >> backup.log
    #Backup Minecraft Servers
    if [ "$backupMinecraft" == "true" ] ; then
        echo "[`date '+%H:%M:%S'`] Minecraft Backup Started" >> backup.log
        for (( servercount = 0; servercount < ${#mcservers[@]}; servercount++ ))
        do
            echo "     ${mcservers[servercount]}" >> backup.log
            tar -zcpf .backups/$timedate/MinecraftServers/${mcservers[servercount]}.tar.gz --directory ${mcservers[servercount]} ${fileexcludes[servercount]} .
        minecraftsize=`expr $minecraftsize + $(ls -la .backups/$timedate/MinecraftServers/${mcservers[servercount]}.tar.gz | awk '{ print $5}')`
        done
        echo "[`date '+%H:%M:%S'`] Minecraft Backup Completed" >> backup.log
    fi
    #Copy MySQL Databases
    if [ "$backupMySQL" == "true" ] ; then
        echo "[`date '+%H:%M:%S'`] MySQL Backup Started" >> backup.log
        for (( sqlcount = 0; sqlcount < ${#sqldatabases[@]}; sqlcount++ ))
        do
            if [[ "${sqldatabases[sqlcount]}" =~ @ ]] ; then
                sqldatabases[sqlcount]=${sqldatabases[sqlcount]//[@]/}
                mysqldump -u"$sqluser" -p"$sqlpass" -h"$sqlhost" ${sqldatabases[sqlcount]} > .backups/$timedate/MySQL/${sqldatabases[sqlcount]}.sql;
                sqlsize=`expr $sqlsize + $(ls -la .backups/$timedate/MySQL/${sqldatabases[sqlcount]}.sql | awk '{ print $5}')`
                echo "     ${sqldatabases[sqlcount]}*" >> backup.log
            else
                mysqldump -u"$sqluser" -p"$sqlpass" -h"$sqlhost" --skip-lock-tables ${sqldatabases[sqlcount]} > .backups/$timedate/MySQL/${sqldatabases[sqlcount]}.sql;
                sqlsize=`expr $sqlsize + $(ls -la .backups/$timedate/MySQL/${sqldatabases[sqlcount]}.sql | awk '{ print $5}')`
                echo "     ${sqldatabases[sqlcount]}" >> backup.log;
            fi
        done
    fi
    #Backup Website
    if [ "$backupWebsite" == "true" ] ; then
        echo "[`date '+%H:%M:%S'`] Website Backup Started" >> backup.log
        if [ "$websiteDirectory" == "default" ] ; then
            websiteDirectory=var/www/
        fi
        if [ -d "$websiteDirectory" ] ; then
            tar -zcpf .backups/$timedate/Website/website.tar.gz --directory $websiteDirectory $websiteExcludes .
            echo "[`date '+%H:%M:%S'`] Website Backup Completed" >> backup.log
        else
            logError "5" "\0044websiteDirectory defined as $websiteDirectory does not exist. Please double check your configuration and make sure this folder exists."
            echo "[`date '+%H:%M:%S'`] Website Backup Cancelled" >> backup.log
        fi
    fi
    #Purge files 3 days old
    if [ "$purgeFiles" == "true" ] ; then
        echo "[`date '+%H:%M:%S'`] Purging Old Backups" >> backup.log
        find .backups* -mmin +$purgeTime -exec rm --recursive {} \;
        echo "[`date '+%H:%M:%S'`] Purging Complete" >> backup.log
    fi
    #Read back file size
    let filesize=$minecraftsize+$sqlsize+$websitesize
    if [ "$filesize" -ge 1024 ] ; then
        if [ "$filesize" -ge 1048576 ] ; then
            if [ "$filesize" -ge 1073741824 ] ; then
                filedivider=1073741824
                fileunit="GB"
            else
                filedivider=1048576
                fileunit="MB"
            fi
        else
            filedivider=1024
            fileunit="KB"
        fi
    else
        filedivider=1
        fileunit="Bytes"
    fi
    let filesized='(''('$filesize%$filedivider')'*100')'/$filedivider
    let filesize=$filesize/$filedivider
    echo "     Total Compression Size: $filesize.$filesized $fileunit" >> backup.log
    if [ "$backupMinecraft" == "true" ] ; then
        if [ "$minecraftsize" -ge 1024 ] ; then
            if [ "$minecraftsize" -ge 1048576 ] ; then
                if [ "$minecraftsize" -ge 1073741824 ] ; then
                    minecraftdivider=1073741824
                    minecraftunit="GB"
                else
                    minecraftdivider=1048576
                    minecraftunit="MB"
                fi
            else
                minecraftdivider=1024
                minecraftunit="KB"
            fi
        else
            minecraftdivider=1
            minecraftunit="Bytes"
        fi
    let minecraftsized='(''('$minecraftsize%$minecraftdivider')'*100')'/$minecraftdivider
    let minecraftsize=$minecraftsize/$minecraftdivider
    logInfo() '2' "none" "Minecraft: $minecraftsize.$minecraftsized $minecraftunit"
    fi
    if [ "$backupMySQL" == "true" ] ; then
        if [ "$sqlsize" -ge 1024 ] ; then
            if [ "$sqlsize" -ge 1048576 ] ; then
                if [ "$sqlsize" -ge 1073741824 ] ; then
                    sqldivider=1073741824
                    sqlunit="GB"
                else
                    sqldivider=1048576
                    sqlunit="MB"
                fi
            else
                sqldivider=1024
                sqlunit="KB"
            fi
        else
            sqldivider=1
            sqlunit="Bytes"
        fi
    let sqlsized='(''('$sqlsize%$sqldivider')'*100')'/$sqldivider
    let sqlsize=$sqlsize/$sqldivider
    echo "          MySQL: $sqlsize.$sqlsized $sqlunit" >> backup.log
    fi
    if [ "$backupWebsite" == "true" ] ; then
        if [ "$websitesize" -ge 1024 ] ; then
            if [ "$websitesize" -ge 1048576 ] ; then
                if [ "$websitesize" -ge 1073741824 ] ; then
                    websitedivider=1073741824
                    websiteunit="GB"
                else
                    websitedivider=1048576
                    websiteunit="MB"
                fi
            else
                websitedivider=1024
                websiteunit="KB"
            fi
        else
            websitedivider=1
            websiteunit="Bytes"
        fi
    let websitesized='(''('$websitesize%$websitedivider')'*100')'/$websitedivider
    let websitesize=$websitesize/$websitedivider
    echo "          Website: $websitesize.$websitesized" >> backup.log
    fi
    echo "" >> backup.log
fi

Как я уже говорил ранее, я полностью потерялся, поэтому буду благодарен за любую помощь. Спасибо!

1
Clucky 9 Апр 2013 в 01:11
Снимите круглые скобки с вызова функции. При вызове функции выглядят как команды.
 – 
Jonathan Leffler
9 Апр 2013 в 01:14

1 ответ

Лучший ответ

Вы не вызываете функцию в круглых скобках. Изменять:

   logInfo() '2' "none" "Minecraft: $minecraftsize.$minecraftsized $minecraftunit"

К

   logInfo '2' "none" "Minecraft: $minecraftsize.$minecraftsized $minecraftunit"
4
William 9 Апр 2013 в 01:19