Redhat 5.3 Enterprise
The following Shell script is used to check and see if a backup directry is named "ll_backup", then changes it to equal the content of a file RESULT.VAR. The result.var file is copied for log purposes to another directory. I had this working in a test enviorenment but in production it throughs a weird error that I can't for the life of me figure out!
SCRIPT:
#!/bin/bash
#!/bin/cat
# Restores original directory name for next LogLogic Update
#TCJ 6/1/09
declare RESULT
declare FILE
FILE=result.var
cd /home/nb-backup/backups/nb-st3000/ll_bkup_65.99.220.172/
if [ -d ll_bkup ]
then
cat result.var | while IFS=: read RESULT
mv "ll_bkup" "$RESULT"
mv result.var /home/storegrid/scripts/results/result-`date +%y%m%d%s`.var
else
exit 0
fi
exit 0
RESULT:
nb-script-restorellbackup.sh: line 14: syntax error near unexpected token
else' nb-script-restorellbackup.sh: line 14:
else'
There are a number of problems, ranging from minor to fatal (all of the fatal ones have to do with the "cat...while...read" line). Let me go through them in order:
Gripe, gripe, gripe... anyway, here's my proposed rewrite:
What's going on with the while loop? It needs
do ... done
somewhere.Here's some reference material for you:
You need to change the line to look like this:
This
cat
andread
looks like to me that it sets $RESULT equal to the first word of the last line of the contents of the file "result.var"and remove this line:
since it's not doing anything.
You don't really need to use
declare
in this situation.Use
$()
around your date command. It's more readable and can be more easily nested, if necessary.