shell script to remove old files and write to a log file

Hi,

I have a script that works on a unix box but am trying to get it working on a linux box that uses shell. I am not a programmer so this is proving harder than I imagined. I made some changes and ended up with the script below but when I run it I get the following messages. Any help would be great.

messages
./cleanoldbackups.sh: line 18: syntax error near unexpected token `fi'
./cleanoldbackups.sh: line 18: `fi '

script
# -----------------------------------------------------------------------
2>&1
# -----------------------------------------------------------------------
# Check run type - r report, d delete
# -----------------------------------------------------------------------
set RUN_TYPE= $1
if [! [$RUN_TYPE == 'r' || $RUN_TYPE == 'd']] then
echo "Invalid parameter" $RUN_TYPE
exit
fi
#
# -----------------------------------------------------------------------
# Set local variables
# -----------------------------------------------------------------------
set LOGFILE= /exlibris/dtl/d3_1/log/cleanoldbackups.log.`date '+%Y%m%d_%H%M%S'`
# -----------------------------------------------------------------------
# Switch to backup directory. Find and report/delete files
# -----------------------------------------------------------------------
cd /directory/backup
#switch $RUN_TYPE
case r
find . -atime +8 | sort | xargs ls -l >>$LOGFILE
breaksw
case d
find . -atime +8 -exec rm {} \; >>$LOGFILE
esac

Try:
if [! [$RUN_TYPE == 'r' || $RUN_TYPE == 'd']] ; then

Also, I am a little concerned about the spacing. In the future, post code with codetags. If you highlight your pasted code text, and then click on the pound # sign above, the forum will maintain your spacing.

hi,

thanks for the tip. i did make the suggested change and ran the script again but got the following messages;

./cleanoldbackups.sh: line 15: [!: command not found
./cleanoldbackups.sh: line 15: ==: command not found
./cleanoldbackups.sh: line 30: syntax error near unexpected token `find'
./cleanoldbackups.sh: line 30: ` find . -atime +8 | sort | xargs ls -l >>$LOGFILE'

2>&1
# --------------------------------------------------------------------------------
# Check run type - r report, d delete
# --------------------------------------------------------------------------------
set RUN_TYPE= $1
  if [! [$RUN_TYPE == 'r' || $RUN_TYPE == 'd']] ; then
  echo "Invalid parameter" $RUN_TYPE
  exit
fi
#
# --------------------------------------------------------------------------------
# Set local variables
# --------------------------------------------------------------------------------
set LOGFILE= /exlibris/dtl/d3_1/log/cleanoldbackups.log.`date '+%Y%m%d_%H%M%S'`
# --------------------------------------------------------------------------------
# Switch to backup directory.  Find and report/delete files not accessed for two weeks.
# --------------------------------------------------------------------------------
cd /san/exlibris1/ueabackup
#switch $RUN_TYPE
   case r
      find .  -atime +8 | sort | xargs ls -l >>$LOGFILE
      breaksw
   case d
      find .  -atime +8 -exec rm {} \; >>$LOGFILE
   esac

Your condition is not correct. Try this:

if [ $RUN_TYPE != 'r' ] && [ $RUN_TYPE != 'd' ] ; then

2>&1
# --------------------------------------------------------------------------------
# Check run type - r report, d delete
# --------------------------------------------------------------------------------
RUN_TYPE=$1
if [ "$RUN_TYPE" != "r" ] && [ "$RUN_TYPE" != "d" ] ; then
echo "Invalid parameter" $RUN_TYPE
exit
fi
--------------------------------------------------------------------------------
# Set local variables
# --------------------------------------------------------------------------------
LOGFILE="/home/cassio/remove.log".`date '+%Y%m%d_%H%M%S'`
# --------------------------------------------------------------------------------
# Switch to backup directory. Find and report/delete files not accessed for two weeks.
# --------------------------------------------------------------------------------
cd /opt/wallis/webserver/logs/

if [ "$RUN_TYPE" == "r" ] ; then
find . -atime +8 | sort | xargs ls -l >>$LOGFILE
elif [ "$RUN_TYPE" == "d" ] ; then
find . -atime +8 -exec rm {} \; >>$LOGFILE
fi