BASH Script syntax error


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting BASH Script syntax error
# 1  
Old 09-02-2008
BASH Script syntax error

I'm trying to write a simple script that takes all the .tar.gz files in a directory and verifies them by using the gzip -tv command:

Code:
for zip in *.tar.gz
  do
          gzip -tv $zip
          if [ #? -eq 0 ] ; then #Check return code from tar
           echo "File ${zip} verified OK." 
           exit 0
          else
              echo "File ${zip} failed to verify. Please check." 
            exit 1
          fi
  done

However, when I try to run this, I get the following error:

Code:
./integcheck.sh: line 10: syntax error near unexpected token `else'
./integcheck.sh: line 10: `          else'

The script looks right to me, can someone help me out with what I missed? Is it a combination of the for/if/then statements?

Thanks!
# 2  
Old 09-02-2008
All,

Never mind, I just saw what was wrong.

I can just do a gzip -tv *.tar.gz to get what I want. Please ignore my post and excuse my morning lack of a intelligence Smilie
# 3  
Old 09-02-2008
Ok, well my idea above worked.. however.. I'm having problems piping the output of the -tv to a log file:
Code:
DATE=`date +%m/%d/%y-%H:%M`
echo "$DATE - Starting Integrity Check...." >> /nmltest/cbpnear/data/mrr/scripts/logs/integ.log
echo "Now Testing all MRR archive files for integrity..."
cd /nmltest/cbpnear/data/mrr/mrr
          gzip -tv *.tar.gz >> /nmltest/cbpnear/data/mrr/scripts/logs/integ.log

Produces this:

Code:
scripts $./integcheck.sh
Now Testing all MRR archive files for integrity...
20080302_1700.tar.gz:    OK
20080303_0800.tar.gz:    OK
20080308_1700.tar.gz:    OK
20080309_0800.tar.gz:    OK

I was hoping the >> would pipe the output shown when running the script to the log file...

any thoughts?
# 4  
Old 09-02-2008
The output is written to standard error, not standard output; you want 2>> instead of just >>
# 5  
Old 09-02-2008
Thanks Era.. I don't know why I didn't see it earlier... much appreciated.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Syntax error in subtraction in Bash

I am sharing a code snippet. for (( i=0; i<=$(( $count -1 )); i++ )) do first=${barr2} search=${barr1} echo $first echo "loop begins" for (( j=0; j<=5000; j++ )) do if } == $search ]]; then echo $j break; fi done second=${harr2} echo $second (2 Replies)
Discussion started by: ngabrani
2 Replies

2. BSD

Keep getting error "-bash: ./.profile_z2: line 52: syntax error: unexpected end of file"

#!/bin/bash #-------------------------------------------------------- # Setup prompt # Author Zeeshan Mirza # Data: 06-08-2017 #-------------------------------------------------------- if then . ./.profile_custom_pre fi umask 022 set -o vi export EDITOR=vi export VISUAL=vi... (3 Replies)
Discussion started by: getzeeshan
3 Replies

3. Shell Programming and Scripting

Bash calling a few functions syntax error

In the bash function below if the user selets "y" then the menu function is called and if they select "n" the move function is called. That all seems to work, my question is after the files are moved an echo, line in bold is displayed and another function called backup is called. I am getting a... (1 Reply)
Discussion started by: cmccabe
1 Replies

4. Shell Programming and Scripting

Bash function using variable in it syntax error

The below bash function uses multiple variables CODING, SAMPLE, SURVEY, andvariant in it. The user selects the cap function and details are displayed on the screen using the $SURVEY variable, the directory is changed to $SAMPLE and the samples.txt is opened so the user can select the sample to... (6 Replies)
Discussion started by: cmccabe
6 Replies

5. Shell Programming and Scripting

-bash: syntax error near unexpected token `('

// AIX 6.1 I am getting a syntax error below. Please advise what to be corrected. :confused: runmqsc CERN.$(echo `hostname` | cut -d'.' -f1 | tr '' '').$(echo $environment | tr '' '') <<! | egrep -i '(FROM.NC.APPLIANCE)' | sort -u |awk '{print $2}' | cut -d '(' -f2 | cut -d ')' -f1 |... (1 Reply)
Discussion started by: Daniel Gate
1 Replies

6. Shell Programming and Scripting

Trying to pass a password: bash: syntax error near unexpected token `('

howdy, so I'm make a plugin work for Nagios, and the commandline is: /usr/lib/nagios/plugins/check_mssql -H MySQLServerName -u MySqlAccountName -p MyPassword(#XXXXX -d MyDatabaseName it is barfing with: bash: syntax error near unexpected token `(' Thoughts? Do I have to wrap something... (2 Replies)
Discussion started by: rgouette
2 Replies

7. Shell Programming and Scripting

Bash syntax error

while read line do mkdir $line scp -r Docking_results/docking_$line.pdb $line/ cd /$line/ set a=`grep ENDMDL docking_'$line'.pdb | wc -l` set b=`expr $a - 2` csplit -k -s -n 3 -f docking_'$line'. docking'$line'.pdb '/^ENDMDL/+1' '{'$b'}' foreach f (... (4 Replies)
Discussion started by: chrisjorg
4 Replies

8. Web Development

Bash Script, ec2addtag syntax?

ec2addtag --region us-west-1 vol1234 --tag Name=$nameinst; It should execute ec2addtag --region us-west-1 vol1234 --tag Name=webserver; Instead it thinks that Name is equal to that variable. Please help. Thanks! Please use code tags! (0 Replies)
Discussion started by: svalenciatech
0 Replies

9. Shell Programming and Scripting

syntax issue mysql in bash script

I'm running mysql in a bash script mysql <<EOF query EOF one query is like this: UPDATE $dbname.$prefix"config" SET value = $var WHERE "$prefix"config.name = 'table colname'; with variable but it's giving an error i'm not sure what to put for "$prefix"config.name the table... (3 Replies)
Discussion started by: vanessafan99
3 Replies

10. Shell Programming and Scripting

bash syntax error: command not found

I am trying to create a shell that asks the user to enter their name, and compare it to my own by saying we have the same name or saying my name and that they have a nice name too. Here is my script... #!/bin/bash-x echo "Enter your name". read name if then echo "My name is Adam too"... (1 Reply)
Discussion started by: amaxey45
1 Replies
Login or Register to Ask a Question