The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
automate sftp using unix script priyamurthy2005 Shell Programming and Scripting 34 02-02-2009 07:36 AM
Script(s) to Automate Tasks droppedonjapan Shell Programming and Scripting 2 05-21-2008 11:32 AM
here document to automate perl script that call script hogger84 Shell Programming and Scripting 3 10-22-2007 11:15 AM
Script to automate file comparisons herman404 Shell Programming and Scripting 6 03-17-2005 08:52 PM
automate the input in a script erwinspeybroeck UNIX for Dummies Questions & Answers 11 01-31-2002 10:54 AM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1 (permalink)  
Old 12-20-2007
barkath barkath is offline
Registered User
  
 

Join Date: Mar 2005
Posts: 12
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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 09:01 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0