LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 09-24-2011, 02:30 PM   #1
Cr0nixx
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Rep: Reputation: Disabled
Question [Backup Script] syntax error near unexpected token `else'


Hello,
i was scripting a Backup Script, that would 7zip a Folder,
what i have is this:

Code:
#!/bin/bash
###############################################################################
#                Backup Script of BigWorld Server (by Cr0nixx)                #
#                                 Version 0.3                                 #
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#
###############################################################################

##### Variables

TIMESTAMP=`date +%H:%M_%d.%m.%Y`
var="."
LOG="/home/bigworldbackup/logs/${TIMESTAMP}.log"
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups`
size2=`du -sb /home/bigworld`
size4="echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc"
counter=$(wc -l < fail.log )
SUBJECT="[BigWorld-Backup-ERROR]"
EMAIL="test@test.de"
EMAIL2="test@test.de"
FINISH="[BigWorld-Backup-Success]"
SERROR="[BigWorld-Backup-FATALERROR]"

##### Variabels end!

#MainCode
if [ -z "$PS1" ]
    then
      clear
      echo -e "\033[36m###############################################################################"
      echo -e "\033[36m#                Backup Script of BigWorld Server (by Cr0nixx)                #"
      echo -e "\033[36m#                                 Version 0.3                                 #"
      echo -e "\033[36m#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#"
      echo -e "\033[36m###############################################################################"
      sleep 0.5
      echo -en "\033[35mChecking if Backup Script of BigWorld Server is running already! ";sleep 0.5;echo -en ".";sleep 0.5;echo -en ".";sleep 0.5;echo -en ".\n"
      if [ -f /home/bigworldbackup/bigworldbackuplock.log ]
        then
          #was found
          echo -e "\n\033[31mERROR:[BigWorldbackuplock.log] was found!"
          echo -e "\033[31mScript is already running!"
          echo -e "\033[31mTry again in a few Minutes!"
          echo -e ""
          echo -e "\033[31m----------------------------------------------------"
          echo -e "\033[31m#\033[33m If this is not going to fix it, contact Cr0nixx! \033[31m#"
          echo -e "\033[31m----------------------------------------------------"
          echo -e ""
          echo -en "\033[35mWriting failed attempt to the Fail.log File! ";sleep 0.4;echo -en ".";sleep 0.4;echo -en ".";sleep 0.4;echo -en ".\n"
          echo "Fail" >> fail.log
          echo -en "\033[35mChecking if we had at least 3 'Fails'";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".\n"
          if [ "2" -ge "$counter" ]
            then
              echo -e "\n\033[32mNope, just $counter Fail(s), try again later!\033[0m"
              echo -e "\033[36m###############################################################################\033[0m"
            else
              echo -en "\033[31mMore than 3 Fails, sending Email! ";sleep 0.4;echo -en ".";sleep 0.4;echo -en ".";sleep 0.4;echo -en ".\n"
              mutt -s $SUBJECT -a /home/bigworldbackup/bigworldbackuplock.log $EMAIL $EMAIL2 < /home/bigworldbackup/failemail.txt
              echo -e "\033[35mEmail finished, clearing Fail.log"
              echo -n "" > fail.log
              echo -e "\033[32mDone!\033[0m"
              echo -e "\033[36m###############################################################################\033[0m"
            fi
        else
          #was not found
          echo -e "\n\033[32mINFO:[BigWorldbackuplock.log] was not found!\n"
          echo -en "\033[35mCreating BigWorldbackuplock.log";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".\n"
          echo "Process running since: $TIMESTAMP" > bigworldbackuplock.log
          echo -e "\033[32mCreated lock File!"
          echo -en "\n\033[35mChecking if we have enough Space!";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".";sleep 0.3;echo -en ".\n"
          if [ ${size4%%$'\t'*} -gt ${size3} ]
            then
              echo -e "NO SPACE LEFT DELETING FILES OLDER THAN 15 DAYS" | tee -a $LOG
              find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +15 -exec rm {} \;
              find /home/bigworldbackup/logs -name "*.log" -type f -mtime +15 -exec rm {} \;
              if [ ${size4%%$'\t'*} -gt ${size3} ]
                then
                  echo -e "NO SPACE LEFT DELETING FILES OLDER THAN 10 DAYS" | tee -a $LOG
                  find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +10 -exec rm {} \;
                  find /home/bigworldbackup/logs -name "*.log" -type f -mtime +10 -exec rm {} \;
                  if [ ${size4%%$'\t'*} -gt ${size3} ]
                    then
                      echo -e "NO SPACE LEFT DELETING FILES OLDER THAN 5 DAYS" | tee -a $LOG
                      find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +5 -exec rm {} \;
                      find /home/bigworldbackup/logs -name "*.log" -type f -mtime +5 -exec rm {} \;
                      if [ ${size4%%$'\t'*} -gt ${size3} ]
                        then
                          echo -e "NO SPACE LEFT, EVEN AFTER DELETING FILES OLDER THAN 5 DAYS, sending Email!" $LOG
                          mutt -s $SERROR $EMAIL $EMAIL2 < /home/bigworldbackup/fatal.txt
                        else
                          echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                          7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                          echo -e "\033[32mBackup finished!" | tee -a $LOG
                          echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                          mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                          echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                          rm -f /home/bigworldbackup/bigworldbackuplock.log
                          echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                          mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                        fi
                    else
                      echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                      7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                      echo -e "\033[32mBackup finished!" | tee -a $LOG
                      echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                      mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                      echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                      rm -f /home/bigworldbackup/bigworldbackuplock.log
                      echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                      mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                    fi
                else
                  echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                  7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                  echo -e "\033[32mBackup finished!" | tee -a $LOG
                  echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                  mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                  echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                  rm -f /home/bigworldbackup/bigworldbackuplock.log
                  echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                  mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                fi
            else          
              echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
              echo -e "\033[32mStarting backup of Bigworld at ${TIMESTAMP}"
              echo -e "Starting Backup in ...3"
              sleep 1
              echo -e "                   ...2"
              sleep 1
              echo -e "                   ...1"
              sleep 1
              7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
              echo -e "\033[32mBackup finished!" | tee -a $LOG
              echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
              mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
              echo -e "Everything is done, Backup was successfull." | tee -a $LOG
              rm -f /home/bigworldbackup/bigworldbackuplock.log
              echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
              mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
              echo -e "\033[36m###############################################################################\033[0m"
            fi
        fi      
    else # ERROR IS RIGHT IN HERE!
      if [ -f /home/bigworldbackup/bigworldbackuplock.log ]
        then
          echo "Fail" >> fail.log
          if [ "2" -ge "$counter" ]
            then
              exit
            else
              mutt -s $SUBJECT -a /home/bigworldbackup/bigworldbackuplock.log $EMAIL $EMAIL2 < /home/bigworldbackup/failemail.txt
              echo -n "" > fail.log
            if
        else
          echo "Process running since: $TIMESTAMP" > bigworldbackuplock.log
          if [ ${size4%%$'\t'*} -gt ${size3} ]
            then
              find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +15 -exec rm {} \;
              find /home/bigworldbackup/logs -name "*.log" -type f -mtime +15 -exec rm {} \;
              if [ ${size4%%$'\t'*} -gt ${size3} ]
                then
                  find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +10 -exec rm {} \;
                  find /home/bigworldbackup/logs -name "*.log" -type f -mtime +10 -exec rm {} \;
                  if [ ${size4%%$'\t'*} -gt ${size3} ]
                    then
                      find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +5 -exec rm {} \;
                      find /home/bigworldbackup/logs -name "*.log" -type f -mtime +5 -exec rm {} \;
                      if [ ${size4%%$'\t'*} -gt ${size3} ]
                        then
                        mutt -s $SERROR $EMAIL $EMAIL2 < /home/bigworldbackup/fatal.txt
                        else
                          echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                          7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                          echo -e "\033[32mBackup finished!" | tee -a $LOG
                          echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                          mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                          echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                          rm -f /home/bigworldbackup/bigworldbackuplock.log
                          echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                          mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                        fi
                    else
                      echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                      7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                      echo -e "\033[32mBackup finished!" | tee -a $LOG
                      echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                      mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                      echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                      rm -f /home/bigworldbackup/bigworldbackuplock.log
                      echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                      mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                    fi
                else
                  echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
                  7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
                  echo -e "\033[32mBackup finished!" | tee -a $LOG
                  echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
                  mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
                  echo -e "Everything is done, Backup was successfull." | tee -a $LOG
                  rm -f /home/bigworldbackup/bigworldbackuplock.log
                  echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
                  mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
                fi
            else
              echo -e "Starting backup of Bigworld at ${TIMESTAMP}" >> $LOG
              7za a -mx9 -mmt -t7z ${TIMESTAMP}.7z /home/bigworld | tee -a $LOG
              echo -e "\033[32mBackup finished!" | tee -a $LOG
              echo -e "Moving $TIMESTAMP.7z to /home/bigworldbackup/backups!" | tee -a $LOG
              mv "${TIMESTAMP}.7z" "/home/bigworldbackup/backups/${TIMESTAMP}.7z"
              echo -e "Everything is done, Backup was successfull." | tee -a $LOG
              rm -f /home/bigworldbackup/bigworldbackuplock.log
              echo -e "Deleted bigworldbackuplock.log, shutting down!" | tee -a $LOG
              mutt -s $FINISH -a /home/bigworldbackup/logs/$TIMESTAMP.log $EMAIL $EMAIL2 < /home/bigworldbackup/successemail.txt
            fi
        fi
fi
I know that the Code is written badly, but its my third Script.

Running it outputs this:
Code:
./test.sh: line 153: syntax error near unexpected token `else'
./test.sh: line 153: `        else'
But the "else" is fitting perfectly there for me ...
Any fix?

Thanks a ton!

Last edited by Cr0nixx; 09-24-2011 at 02:40 PM.
 
Old 09-24-2011, 02:41 PM   #2
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,692

Rep: Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987Reputation: 1987
So did you go to the line in the code? Seems fairly obvious:
Code:
echo -n "" > fail.log
if
else
    echo "Process running since: $TIMESTAMP" > bigworldbackuplock.log
 
1 members found this post helpful.
Old 09-24-2011, 02:43 PM   #3
Cr0nixx
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
So did you go to the line in the code? Seems fairly obvious:
Code:
echo -n "" > fail.log
if
else
    echo "Process running since: $TIMESTAMP" > bigworldbackuplock.log
right wrote if, should be fi
Testing: Working fine, only got this error ./test.sh: line 70: [: too many arguments

thats this line:
Code:
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups`
size2=`du -sb /home/bigworld`
size4="echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc"
if [ ${size4%%$'\t'*} -gt ${size3} ]

Last edited by Cr0nixx; 09-24-2011 at 02:48 PM.
 
Old 09-24-2011, 03:14 PM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
First of all, please don't use php code tags. For some reason they don't wrap properly, and cause very annoying side scrolling. Not to mention that this is a bash script, not php. Just use regular code tags like everyone else.

Second, your code is really hard to parse. You need to break up sections with blank lines, so that each loop can be more clearly seen as a separate unit. That alone would probably help you to parse out your error.

Making sure all the keywords in the loops and constructs line up on the same column would also help. Try putting the "do/then" keywords on the same line as the for/while/if, and line up the beginning and ending keywords. i.e. for should line up with done, if with fi, case with esac, etc. Then line up all subcommands on the same column inside the construct. In short, every command at the same logical nesting level should start on the same column.

Finally, realize that the line given in the error message is the point at which the syntax parser becomes too confused to continue processing the commands. This is not always the point where the error exists. It may be that you have forgotten to close up a command somewhere further up, and it doesn't cause an error until the parser hits something further down that conflicts with it. So start walking your way backwards from the error point until you find the actual syntax error.

Now let's look at one of the code blocks near the place where you got the error:
Code:
if [ -f /home/bigworldbackup/bigworldbackuplock.log ]; then
          echo "Fail" >> fail.log
          if [ "2" -ge "$counter" ]
            then
              exit
            else
              mutt -s $SUBJECT -a /home/bigworldbackup/bigworldbackuplock.log $EMAIL $EMAIL2 < /home/bigworldbackup/failem$
              echo -n "" > fail.log
            if
   else
If we apply the formatting suggestions I made above, it would look more like this:
Code:
if [ -f /home/bigworldbackup/bigworldbackuplock.log ]; then
	echo "Fail" >> fail.log

	if [ "2" -ge "$counter" ]; then
		exit
	else
		mutt -s $SUBJECT -a /home/bigworldbackup/bigworldbackuplock.log $EMAIL $EMAIL2 < /home/bigworldbackup/failem$
		echo -n "" > fail.log
	if

else
Well, look at that. Assuming I'm properly picking the loop out of your code, it appears that your if statement is closed by another if, rather than the fi it should have been closed with.

Last edited by David the H.; 09-24-2011 at 03:17 PM. Reason: Removed superfluous misedit
 
1 members found this post helpful.
Old 09-24-2011, 03:30 PM   #5
Cr0nixx
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
@ David the H.

Thanks

Sorry for this Mess, but im a Beginner and learning

anyone got a solution for this?

Code:
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups`
size2=`du -sb /home/bigworld`
size4="echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc"
if [ ${size4%%$'\t'*} -gt ${size3} ] # too many arguments here :/
 
Old 09-24-2011, 03:35 PM   #6
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Here's another suggestion. You'd make your code even more readable by moving repetitive commands into functions.

All of these find commands, in particular:
Code:
find /home/bigworldbackup/backups -name "*.7z" -type f -mtime +15 -exec rm {} ;
I'd put these into a function like this at the top of the script:
Code:
removefiles() {
	#Use the find command to remove files of a certain type and age.
	#$1 is the directory to search.
	#$2 is the pattern to search
	#$3 is the mtime range to match

	find "$1" -name "$2" -type f -mtime "$3" -exec rm {} \+  # (or gnu find has a -delete option)

}
...And call it like this:
Code:
removefiles '/home/bigworldbackup/backups' '*.7z' '+15'
I'd also add a few more comments explaining the logic behind what the code is doing. You'll be happy you did a few years down the line when you review the code and wonder just what the heck you were high on when you wrote it.
 
1 members found this post helpful.
Old 09-24-2011, 03:47 PM   #7
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Quote:
Originally Posted by Cr0nixx View Post
anyone got a solution for this?

Code:
if [ ${size4%%$'\t'*} -gt ${size3} ] # too many arguments here :/
[ is a command, just like any other, with the entries following it all being arguments to that command (with a closing bracket being the last argument). In the pattern "x -gt y", there are logically only 3 arguments: x, -gt, and y.

So are there three arguments? What do the variables ${size4%%$'\t'*} and ${size3} actually output? Remember that word-splitting occurs when you don't quote variables.

Try inserting set -x and set +x before and after the affected to toggle verbose output, which will help you debug what your script is doing.


But actually, in bash, arithmetic arguments are better tested with ((..)), and string arguments with [[..]].

http://mywiki.wooledge.org/ArithmeticExpression
http://mywiki.wooledge.org/BashFAQ/031

There's more on debugging and other good code practices here:
http://mywiki.wooledge.org/BashGuide/Practices
 
1 members found this post helpful.
Old 09-24-2011, 03:51 PM   #8
Cr0nixx
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
here you go
Code:
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups` # get size of the folder ,where the backups are stored.
size2=`du -sb /home/bigworld` # get size of the folder to backup
size4="echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc" #size + size2 = size4
if [ ${size4%%$'\t'*} -gt ${size3} ] # too many arguments here :/ | if size 4 bigger than size3(10gb) than delete old backups, if not do backup

Last edited by Cr0nixx; 09-24-2011 at 03:55 PM.
 
Old 09-24-2011, 04:06 PM   #9
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
Quote:
Originally Posted by Cr0nixx View Post
here you go
Code:
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups` # get size of the folder ,where the backups are stored.
size2=`du -sb /home/bigworld` # get size of the folder to backup
size4="echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc" #size + size2 = size4
if [ ${size4%%$'\t'*} -gt ${size3} ] # too many arguments here :/ | if size 4 bigger than size3(10gb) than delete old backups, if not do backup
Hi,

I think you are missing the command substitution. What you probably want is:
Code:
size3=10737418240 # 10 gb space
size=`du -sb /home/bigworldbackup/backups` # get size of the folder ,where the backups are stored.
size2=`du -sb /home/bigworld` # get size of the folder to backup
size4=$(echo -e "${size%%$'\t'*}+${size2%%$'\t'*}" | bc) #size + size2 = size4
if [ ${size4} -gt ${size3} ] # too many arguments here :/ | if size 4 bigger than size3(10gb) than delete old backups, if not do backup
Notice, that you do not need String manipulation for $size4 since it does not contain any tabs.
 
1 members found this post helpful.
Old 09-24-2011, 04:10 PM   #10
Cr0nixx
LQ Newbie
 
Registered: Sep 2011
Posts: 8

Original Poster
Rep: Reputation: Disabled
@ crts

Thank you very much its working
 
Old 09-24-2011, 04:19 PM   #11
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,604

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
You are welcome. If there are no other errors then please mark the thread as solved.
 
Old 09-24-2011, 05:32 PM   #12
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Debian sid + kde 3.5 & 4.4
Posts: 6,823

Rep: Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950Reputation: 1950
Go ahead and replace all the other `..` backticks with $(..) as well, while you're at it.

http://mywiki.wooledge.org/BashFAQ/082

Speaking of which, how do you newbies keep getting taught the old form anyway? The new syntax has been around for ages, is defined by posix, and is supported by all the major bourne-based shells. All of the guides I've ever seen make it clear that the backticks are deprecated. So just where are you getting your scripting information?
 
Old 09-27-2011, 02:37 PM   #13
goossen
Member
 
Registered: May 2006
Location: Bayern, Germany
Distribution: Many
Posts: 224

Rep: Reputation: 41
I'd like to recommend another good website for anybody wanting to learn more about bash scripting. It helped me many times!

http://wiki.bash-hackers.org/start
 
  


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
Bash script problem: syntax error near unexpected token `do rmaier9 Programming 3 08-21-2014 06:20 AM
./script.sh: line 2: syntax error near unexpected token `(' n00balert Programming 3 03-11-2010 05:22 PM
why is my shell script giving me - syntax error near unexpected token 'enterInfo() chisunum Linux - Newbie 3 10-23-2009 04:37 PM
syntax error near unexpected token Aigarzs Linux - Newbie 3 01-12-2008 04:39 PM
syntax error near unexpected token deskjockey39 Linux - General 2 01-16-2007 09:47 AM


All times are GMT -5. The time now is 05:44 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration