script to automate mksysb via nim in AIX 5.3

#!/bin/ksh
#
# nim_mksysb [-h] [-r] [-n] [-l] [-m 'machines to get mksysb from']
# get mksysb from each client machine specified with -m. If no
# machines specified, get mksysb from ALL machines. -r flag says
# remove oldest existing mksysb for the machines being backed up.
# use -n no_make flag with -r to remove a generation of mksysb,
# without creating a new one.
# Added subdirectory for each nim_machine
# Added help (-h)
# Added list (-l)
# Added MAX_BACKUPS (save up to MAX_BACKUPS, then erase oldest)

### Your customizations begin here ###

# Parent directory for storing mksysb
# Backups will be stored as $MKSYSB_DIR/nim_machine_name/nim_machine_name_date
MKSYSB_DIR=/export/mksysb

# Save up to MAX_BACKUPS per server, then remove oldest (space saving)
# The "-r" option will override and remove the oldest.
MAX_BACKUPS=100

### End customizations ###

# Initialize
remove_old=
machine_list=
no_make=

# Get Command Line Arguments
while getopts hlnrm: option
do
case $option in
h) echo " "
echo "Purpose: automate system backup(s) using NIM"
echo " "
echo "Syntax: `basename $0` [-h] [-r] [-n] [-l] [-m 'machines to get mksysb from']"
echo "\t-h = help"
echo "\t-r = remove the oldest mksysb image"
echo "\t-l = list NIM machines and mksysb images"
echo "\t-n = no backup (used for testing or to remove oldest mksysb)"
echo "\t-m = NIM machine name to backup. Default = backup all"
echo ""
exit;;

l) echo "\n## NIM machines ##"
lsnim -c machines | awk ' !/^master/ { print $1 } '
echo "\n## NIM mksysb Resources ##"
lsnim -t mksysb | awk ' { print $1 }'
echo " "
exit;;

m) machine_list="$OPTARG";;
n) no_make=1;;
r) remove_old=1;;
esac

done

# if machine_list is null at this point, set it to ALL clients
if [ -z "$machine_list" ]; then
machine_list=`lsnim -c machines | awk ' !/master/ { print $1 }'`
fi

# Backup machine(s)
echo "Machine list is $machine_list \n"

for m in $machine_list
do

echo "### Creating NIM mksysb Resource for $m ###"
date

if [ ! -d $MKSYSB_DIR/$m -a -z "$no_make" ]; then
echo "Creating new directory: $MKSYSB_DIR/$m"
mkdir $MKSYSB_DIR/$m
fi

cd $MKSYSB_DIR/$m 2>/dev/null

n_backups=$(ls $m* |wc -l )
if [ ! -z "$remove_old" || $n_backups -ge $MAX_BACKUPS ]; then
oldest=$(ls -lt $m* | tail -1 | awk '{print $9}')
if [ ! -z $oldest ]; then
echo Removing oldest file and nim resource: $oldest
nim -o remove $oldest
/usr/bin/rm $oldest
else
echo "Can not remove oldest file. No files to remove. $oldest"
fi
fi

# if no_make is null, go ahead and make the mksysb
if [ -z "$no_make" ]; then

  filename="$m"_\`date \+%Y%m%d%H%M\`

  echo New file and nim resource is $filename
  echo Machine to backup is $m

  echo nim -o define -t mksysb -aserver=master -amk_image=yes \\
  -alocation=$MKSYSB_DIR/$m/$filename \\
  -asource=$m $filename

  time nim -o define -t mksysb -aserver=master -amk_image=yes \\
  -alocation=$MKSYSB_DIR/$m/$filename \\
  -asource=$m $filename

else
echo "Script invoked with no_make option. Backup of $m was not made."
fi
echo "-----"

done

=======================================
OUTPUT generated from the above script

### Creating NIM mksysb Resource for aixlib1 ###
Thu Dec 20 16:28:31 CST 2007
Creating new directory: /export/mksysb/aixlib1
ls: 0653-341 The file aixlib1* does not exist.
./mksysb2.sh[86]: test: 0403-021 A ] character is missing.
./mksysb2.sh[86]: 0: not found.
New file and nim resource is aixlib1_200712201628
Machine to backup is aixlib1

The above script automates system backup via NIM on AIX 5.3 and runs OK except that it gives the above errors (character is missing, 0: not found) , looks like I'm overlooking something here, any help is very much appreciated. Thanks