BASH function: syntax error near unexpected token `'2'' -
i lost why error keeps happening, using correct syntax, however, every time execute bash script, following error:
/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"'
the line in particular appears refrencing line 200, code attempts execute function loginfo()
follows:
loginfo() '2' "none" "minecraft: $minecraftsize.$minecraftsized $minecraftunit"
in above line of code, 2
indent level (2 x 5 spaces). none
tells function ignore loglevel
specified in configuration , log anyway. minecraft: $minecraftsize...$minecraftunit
being added log file, words preceeded $ of course variables. entire code can viewed below.
#! /usr/bin/env bash #declare functions loginfo() { if [ "$loginfile" == "true" ] || [ "$loginconsole" == "true" ] ; let tabamount=5*$1 indent="" (( indentrepeat=0; indentrepeat < $tabamount; indentrepeat++ )) indent="$indent " done if [ "$2" == "none" ] ; infoitem="$3" else if [ "$loglevel" == "high" ] ; if [ "$2" == "subtask" ] ; #high + subtask infoitem="`date '+%h:%m:%s'` $3" elif [ "$2" == "task" ] ; #high + task infoitem="`date '+%h:%m:%s'` $3" fi elif [ "$loglevel" == "medium" ] ; if [ "$2" == "subtask" ] ; #medium + subtask infoitem="$3" elif [ "$2" == "task" ] ; #medium + task infoitem="`date '+%h:%m:%s'` $3" fi else if [ "$2" == "subtask" ] ; #low + subtask infoitem='' elif [ "$2" == "task" ] ; #low + task infoitem="$3" fi fi fi if [ "$loginfile" == "true" ] ; echo -e "$indent$infoitem" >> backup.log fi if [ "$loginconsole" == "true" ] ; echo -e "$indent$infoitem" fi fi } logerror() { if [ "$loginfile" == "true" ] || [ "$loginconsole" == "true" ] ; let tabamount=5*$1 indent="" (( indentrepeat=0; indentrepeat < $tabamount; indentrepeat++ )) indent="$indent " done if [ "$loginfile" == "true" ] && [ "$logerrors" == "true" ] ; echo -e "$indent[error] $2" >> backup.log fi if [ "$loginconsole" == "true" ] && [ "$logerrors" == "true" ] ; 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" ] ; source update.sh fi #trigger general settings echo -ne "\033]0;$servername - backup\007" if [ "$serverdirectory" == "default" ] ; bindir="$(dirname "$(readlink -fn "$0")")" cd "$bindir" else if [ -d "$serverdirectory" ] ; cd "$serverdirectory" else directoryexists=false echo '$serverdirectory defined '"$serverdirectory"' not exist. please double check configuration , make sure folder exists.' if [ "$loginfile" == "true" ] ; echo "-------------- `date '+%d-%b-%y %h:%m'` --------------" >> backup.log echo -e ' [error] $serverdirectory defined '"$serverdirectory"', not exist. please double check configuration , make sure folder exists.'"\n" >> backup.log fi fi fi if [ "$purgefiles" == "true" ] || [ "$backupminecraft" == "true" ] || [ "$backupmysql" == "true" ] || [ "$backupwebsite" == "true" ] && [ "$directoryexists" != "false" ] ; echo "-------------- `date '+%d-%b-%y %h:%m'` --------------" >> backup.log #create directories echo "[`date '+%h:%m:%s'`] directory creation started" >> backup.log if [ ! -d ".backups" ] ; mkdir -p .backups fi mkdir -p .backups/$timedate if [ "$backupmysql" == "true" ] ; mkdir -p .backups/$timedate/mysql fi if [ "$backupwebsite" == "true" ] ; mkdir -p .backups/$timedate/website fi if [ "$backupminecraft" == "true" ] ; mkdir -p .backups/$timedate/minecraftservers fi echo "[`date '+%h:%m:%s'`] directory creation completed" >> backup.log #backup minecraft servers if [ "$backupminecraft" == "true" ] ; echo "[`date '+%h:%m:%s'`] minecraft backup started" >> backup.log (( servercount = 0; servercount < ${#mcservers[@]}; servercount++ )) 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" ] ; echo "[`date '+%h:%m:%s'`] mysql backup started" >> backup.log (( sqlcount = 0; sqlcount < ${#sqldatabases[@]}; sqlcount++ )) if [[ "${sqldatabases[sqlcount]}" =~ @ ]] ; 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" ] ; echo "[`date '+%h:%m:%s'`] website backup started" >> backup.log if [ "$websitedirectory" == "default" ] ; websitedirectory=var/www/ fi if [ -d "$websitedirectory" ] ; 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 $websitedirectory not exist. please double check configuration , make sure folder exists." echo "[`date '+%h:%m:%s'`] website backup cancelled" >> backup.log fi fi #purge files 3 days old if [ "$purgefiles" == "true" ] ; 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 file size let filesize=$minecraftsize+$sqlsize+$websitesize if [ "$filesize" -ge 1024 ] ; if [ "$filesize" -ge 1048576 ] ; if [ "$filesize" -ge 1073741824 ] ; 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" ] ; if [ "$minecraftsize" -ge 1024 ] ; if [ "$minecraftsize" -ge 1048576 ] ; if [ "$minecraftsize" -ge 1073741824 ] ; 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" ] ; if [ "$sqlsize" -ge 1024 ] ; if [ "$sqlsize" -ge 1048576 ] ; if [ "$sqlsize" -ge 1073741824 ] ; 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" ] ; if [ "$websitesize" -ge 1024 ] ; if [ "$websitesize" -ge 1048576 ] ; if [ "$websitesize" -ge 1073741824 ] ; 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
as stated earlier, lost, assistance appreciated. thank you!
you don't invoke function parentheses. change:
loginfo() '2' "none" "minecraft: $minecraftsize.$minecraftsized $minecraftunit"
to
loginfo '2' "none" "minecraft: $minecraftsize.$minecraftsized $minecraftunit"
Comments
Post a Comment