Dear All, I am new to korn scripts the below mention scripts for taking the system backup in NIM environment its looks okay but its not removing the old objects& system backup for more specific i am getting error on line number 83

Need help pls

#!/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/eznim/mksysb/ 

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

### 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

A couple of questions
Why is stderr redirected to /dev/null in line 80?
What error do you get in line 83?

A couple of questions
Why is stderr redirected to /dev/null in line 80?
What error do you get in line 83?

i think to display the error that's why its redirected

Error has mention below

# ./mksysb.scripts[83]: test: 0403-021 A ] character is missing.
./mksysb.scripts[83]: 7: not found.

It's been a while since I've done any real scripting but shouldn't

if [ ! -z "$remove_old" || $n_backups -ge $MAX_BACKUPS ]; then

be

if [ ! -z "$remove_old" -o $n_backups -ge $MAX_BACKUPS ]; then
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.