Friday, December 31, 2010
Command Line Init Script Generator For Linux Or Unix
Hey There,
To start this week off, we've got another updated script (now that we have over 600 some odd posts, we actually have about 400 some odd loose ends to finish up, as well ;) This script is an update of an earlier post we did to showcase a basic init script generator for Linux or Unix , again hearkening back to 2007. How time flies when you're not paying attention to what you're doing ;)
This script includes several updates (which haven't been tested to perfection - so feel free to write in with complaints ;) such as the ability to use command line arguments to specify a wider variety of options, set some to default and not even enter any (except three) if you don't want to. Actually, the only three required arguments are the name of the program you want to start with the init script you generate, the fully qualified name of the same program and the name of the init script itself. All the other options are easily displayed by just running the command without any arguments, like so:host # ./rcscript.sh
Options -n -p and -f are required!
Usage: ./rcscript.sh [-h for this help screen]
Required switches:
[-n init script name] [-p name of program to control]
[-f controlled program's fully qualified name]
Optional switches:
[-i init directory] [-3 rc3.d directory] [-0 rc0.d directory
[-s start options for your program]
[-S stop options for your program]
[-k additional programs to kill on stop - space separated]
[-b common binary directory - defaults to /usr/bin]
Be sure to "double quote" any switch arguments with spaces!
Hope you enjoy the updates and this script helps you out in some way or fashion :)
Cheers,
Creative Commons License
rcscript.sh by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Based on a work at linuxshellaccount.blogspot.com.
Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com.#!/bin/sh
#
# Generic Init Script Creator
# 2009 - Mike Golvach - eggi@comcast.net
#
#Creative Commons License
rcscript.sh by Mike Golvach is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 United States License.
Based on a work at linuxshellaccount.blogspot.com.
Permissions beyond the scope of this license may be available at http://linuxshellaccount.blogspot.com.
#
trap 'rm -f ${init_dir}/${script_name} ${rc3_dir}/${script_name} ${rc0_dir}/${script_name} ${script_name}' 1 2 3 9 15
# Tips for a few command line arguments - setting an argument to zero will not be considered equivalent to not defining it
# a. set init_dir to 0 if you don't want any scripts and links setup - set rc3_dir, rc2_dir and/or init_dir to "0" to not create that link/script.
# b. If any of the init_dir, rc2_dir and/or rc3_dir variables are not set, they will default to the examples below.
# c. options that include 0 in the example do not need to be set and are entirely optional
#
# init_dir= /etc/init.d or 0
# rc3_dir= /etc/rc3.d or 0
# rc0_dir= /etc/rc0.d or 0
# script_name= myStartScript.sh
# program_name= testProgram
# fully_qualified_program_name= /usr/local/sbin/testProgram
# start_options= "start" or 0
# stop_options= "stop" or 0
# sure_kill= "space delimited list of extra programs to kill" or 0
# common_bin_directory= "place where common binaries are on your system" or defaults to /usr/bin
#
function usage()
{
echo
echo "Usage: 0ドル [-h for this help screen]"
echo
echo "Required switches:"
echo "[-n init script name] [-p name of program to control]"
echo "[-f controlled program's fully qualified name]"
echo
echo "Optional switches:"
echo "[-i init directory] [-3 rc3.d directory] [-0 rc0.d directory"
echo "[-s start options for your program]"
echo "[-S stop options for your program]"
echo "[-k additional programs to kill on stop - space separated]"
echo "[-b common binary directory - defaults to /usr/bin]"
echo
echo "Be sure to \"double quote\" any switch arguments with spaces!"
echo
exit 1
}
while getopts 0:3:b:f:hi:k:n:p:s:S: option
do
case $option in
'i')
if [[ "$OPT_ARG" == "0" ]]
then
init_dir=0
else
init_dir="$OPTARG"
fi
;;
'3')
if [[ "$OPT_ARG" == "0" ]]
then
rc3_dir=0
else
rc3_dir="$OPTARG"
fi
;;
'0')
if [[ "$OPT_ARG" == "0" ]]
then
rc0_dir=0
else
rc0_dir="$OPTARG"
fi
;;
'n')
script_name="$OPTARG"
;;
'p')
program_name="$OPTARG"
;;
'f')
fully_qualified_program_name="$OPTARG"
;;
's')
if [[ "$OPT_ARG" == "0" ]]
then
start_options=""
else
start_options="$OPTARG"
fi
;;
'S')
if [[ "$OPT_ARG" == "0" ]]
then
stop_options=""
else
stop_options="$OPTARG"
fi
;;
'k')
if [[ "$OPT_ARG" == "0" ]]
then
additional_kills=""
else
additional_kills="$OPTARG"
fi
;;
'b')
if [[ "$OPT_ARG" == "0" || -z "$OPT_ARG" ]]
then
common_bin_directory="/usr/bin"
else
common_bin_directory="$OPTARG"
fi
;;
'h')
usage
;;
*)
usage
;;
esac
done
if [[ -z $script_name || -z $program_name || -z $fully_qualified_program_name ]]
then
echo
echo "Options -n -p and -f are required!"
usage
fi
if [[ -z $common_bin_directory ]]
then
common_bin_directory="/usr/bin"
fi
if [[ -e $script_name ]]
then
rm $script_name
fi
cat << EOM >>$script_name
#!/bin/sh
#
# ${program_name} init script
# Usage: $script_name [start|stop|restart]
#
case \1ドル in
'start')
echo
echo Starting ${program_name}....
echo
${fully_qualified_program_name} ${start_options} >/dev/null 2>&1 &
${program_name}_running=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \2ドル}'\`
if [ "\$${program_name}_running" == "" ]
then
echo "${program_name} start cannot be confirmed. Please check"
echo "system output and application logs for further detail"
else
echo "${program_name} started successfully"
fi
;;
'stop')
echo
echo Stopping ${program_name}....
echo
if [ "$stop_options" != " " ]
then
${fully_qualified_program_name} ${stop_options} >/dev/null 2>&1 &
fi
${program_name}_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \2ドル}'\`
if [ "\$${program_name}_walking" == "" ]
then
echo "${program_name} does not appear to be running."
echo "Process not found. Not shut down."
else
counter=5
dead="alive"
echo "Shutting ${program_name} down."
echo "${fully_qualified_program_name} - pid ${program_name}_walking - stopping."
while [ \$counter -gt 0 ]
do
${program_name}_still_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \2ドル}'\`
if [ "\$${program_name}_still_walking" != "" ]
then
echo "killing pid \$${program_name}_still_walking "
${common_bin_directory}/kill \$${program_name}_still_walking
counter=\`expr \$counter - 1\`
sleep 1
else
dead="dead"
echo "dead"
counter=0
fi
done
if [ \$dead = "alive" ]
then
echo "Could not kill process after 5 attempts."
echo "Process ${program_name}_walking still active."
${common_bin_directory}/ps -ef|${common_bin_directory}/grep "${fully_qualified_program_name}"|${common_bin_directory}/grep -v grep
fi
fi
EOM
if [[ $additional_kills && ! -z $additional_kills ]]
then
cat << EOM >>$script_name
for aks in `echo $additional_kills`
do
echo
echo Stopping \$aks....
echo
aks_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \2ドル}'\`
if [ "\$aks_walking" == "" ]
then
echo "\$aks does not appear to be running."
echo "Process not found. Not shut down."
else
counter=5
dead="alive"
echo "Shutting \$aks down."
echo "\$aks - pid \$aks_walking - stopping."
while [ \$counter -gt 0 ]
do
aks_still_walking=\`${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep|${common_bin_directory}/awk '{print \2ドル}'\`
if [ "\$aks_still_walking" != "" ]
then
echo "killing pid \$aks_still_walking "
${common_bin_directory}/kill \$aks_still_walking
counter=\`expr \$counter - 1\`
sleep 1
else
dead="dead"
echo "dead"
counter=0
fi
done
if [ \$dead = "alive" ]
then
echo "Could not kill process after 5 attempts."
echo "Process \$aks_walking still active."
${common_bin_directory}/ps -ef|${common_bin_directory}/grep "\$aks"|${common_bin_directory}/grep -v grep
fi
fi
done
EOM
fi
cat << EOM >>$script_name
;;
'restart')
echo
echo ReStarting ${program_name}....
echo
\0ドル stop
\0ドル start
;;
*)
echo "Usage: \0ドル [start|stop|restart]"
;;
esac
EOM
${common_bin_directory}/chmod 750 ${script_name};
${common_bin_directory}/cp ${script_name} ${init_dir}/${script_name}
${common_bin_directory}/ln -s ${init_dir}/${script_name} ${rc3_dir}/${script_name}
${common_bin_directory}/ln -s ${init_dir}/${script_name} ${rc0_dir}/${script_name}
, Mike
Please note that this blog accepts comments via email only . See our Mission And Policy Statement for further details.
Thursday, April 16, 2009
Beginner's Shell Scripting On Linux And Unix: Why And How
Hey There,
Recently I was asked a very simple question that I'm pretty sure I've never addressed in this blog over the mass of posts already churned out. Shell scripting has been addressed, to a great degree, on this blog, but (even the beginner stuff) has included a presumption of certain knowledge. It's easy to forget what it was like back when I started working on Linux and Unix, so I often make the cardinal sin of assuming everyone has already asked this question and had it answered.
The question was simple (although, a three-parter) : I know how to use Unix/Linux enough to get around on the command line, but why would I want to write shell scripts? And how do I write a shell script, anyway? Isn't it just going to be more hassle than I already have to deal with?
The above was only-slightly paraphrased ;)
So, even though I could dump these questions, and their answers, off by conveniently linking to any number of other sites, I thought it might be a good idea to just answer them here. I've never posted on the subject before and it can't hurt to have this basic information available in our site search.
IMPORTANT NOTE FOR LINUX/UNIX USER'S AND SHELL SCRIPTERS WHO CAN ANSWER ALL THREE QUESTIONS: This post is probably going to be very boring for you ;) I'll do my best to see that it doesn't come off too dry, but I won't be writing about anything you don't know already, and I will be purposefully leaving out certain things that may drive you crazy ;)
So, to attack the question, I've decided to respond in two parts (since the final two naturally flow together) and keep this post as simple as possible. My feeling is that if you're reading this and aren't sure what shell scripting is and/or why you should even bother to make use of it, you're not looking to be weighed down by a ton of technical jargon and over-explanation which would probably just cloud the issue and be more difficult to understand than necessary. Here we go :)
Q: Why would I want to write shell scripts? Isn't it just going to be more hassle than I already have to deal with?
A: To answer the question "Why?," the most succinct answer would be "Why Not?" There are several good reasons to write shell scripts (for your own use or for the use of others), one of which addresses the "hassle" issue ;)
1. Shell scripting, at its most basic, is actually very easy to master (assuming that you can get around well enough on the Unix or Linux command line to accomplish whatever it is you need to do). In fact, your knowledge of the command line will be almost-directly commensurate with your ability to write shell scripts of varying complexity.
2. Writing a shell script is only slightly (and I mean "very" slightly) more of a hassle than doing the exact same thing on the command line. It can, very literally, be thought of as a way of saving your command line work so that you never have to worry about remembering it ever again.
3. If you've written a shell script once, you never have to write it again (unless you want to improve, or modify, it - well, you can have your own reasons. It's none of my business, anyway ;). If you hammer out a command line to get your chores done (assuming you don't have one of many other methods of saving command line history enabled), you're going to need to keep hammering out that command line every time you do your work.
4. For a very basic example of how writing simple shell scripts can "save" you from hassle. Consider the following situation:
Every day at work you come in, log in to your Unix/Linux terminal and type:host # cd /my/main/work/directory
host # ls |grep myuserid.txt
host # rm myuserid.txt
host # find . -name core -print >>myuserid.txt
host # cat myuserid.txt|xargs rm -f
host # cd
While that example above illustrates more than a few opportunities for improvement, that's not today's issue ;) Now imagine if, instead of logging in to your Unix/Linux terminal and grinding out those six lines, all you had to do was log in and type the following (we're keeping this so basic and simple, we're not even going to deal with using the shebang line in your script or setting the script up to be executable on its own):
host # /bin/bash myscript
Much less hassle, yeah? :)
Q: How do I write a shell script, anyway?
A: It's actually extremely simple (and we're keeping it extremely simple for now). There are a lot more steps you can take to make the whole perception of "hassle" wither even further, as well as make your script writing even more convenient for you, but that's for another day. I'm fighting every instinct in my head to try and keep this as "basic" as possible and not introduce any "logical constructs" or "error checking" into your first script.
The first thing to consider, when answering this question, is another question. "What" is a shell script, anyway? It goes a long way to making the "how" obvious. A shell script, in its most pristine state, is simply a collection of command lines. No joking. That's all it has to be, and it can be just that simple.
Consider the example above (point number 4 of the answer to the first question). If you simply take all those lines that you type everyday and put them in a file, you will have written your first shell script! So, open up your favorite editor and either straight-type or cut-and-paste all those lines into it. It's very important, since we're not going to address issues of efficiency beyond the basic, that you type each command line on a separate line in your new file. It should look exactly like this (your commands may differ, of course ;)cd /my/main/work/directory
ls |grep myuserid.txt
rm myuserid.txt
find . -name core -print >>myuserid.txt
cat myuserid.txt|xargs rm -f
cd
Save that file as "myscript" (or whatever else you'd rather call it) and you're all done. You've written your first shell script!
Now, instead of typing 6 lines of commands, you only have to type one. Since we're not getting into setting up your shell script to be executable on its own, you just need to invoke it with a shell (preferably the one you use to type those commands with every day). If you're not sure what shell you use, you can find out that information by simply typing the following at the command line:
host # echo $SHELL
/bin/bash
and, assuming that your environment variables are all set up correctly (arggh, losing focus... ;), that command will return the value of your shell. Now you can execute your shell script easily in either one of two ways.
a. If you're in the same directory as your script, you can execute it by running:
host # /bin/bash myscript
b. If you're not in the same directory as your script, or prefer to use full paths, you can invoke it like this:
host # /bin/bash /directory/where/the/script/is/myscript
and all of your commands will be executed, in order, as if you had manually typed them at the command line yourself.
That, in an nutshell, is the how and the why of writing a basic shell script. It should also address the "hassle" issue ;) Taking this simple example (and learning no more about how to create shell scripts than you've learned so far), you'll probably realize that there are several other things you do every day (all of which require prodigious typing) that you can put into shell scripts and stave off carpal-tunnel syndrome for at least a little while longer ;)
Over time, you should begin to experience the convenience shell scripting has to offer you and become curious about how much more it can help you by reducing the hassle of your workaday tasks and introducing automation of the mundane. Eventually, you may even become interested in more advanced concepts and begin to enjoy the full benefit of shell scripting.
The main thing to keep in mind (no matter how complex your shell script ever becomes) is that a shell script (shebang line excluded) is merely a collection of commands that you could run, yourself, from the command line. Keep in mind, also, that your shell includes many features that were not showcased here today. Even when you avail yourself of those, any shell script can be written on the command line and anything you can write on the command line can easily become a shell script.
I hope that long-winded answer to a fairly short (but definitely loaded ;) question was of some help to you. If you're interested in learning more, search around this blog or elsewhere on the Internet. If you can't find the answer to a question you have, feel free to email me via the link at the top right of the page. My response time isn't what it used to be (before I began inviting people to write me ;), but I will get back to you as soon as I can.
As a final exercise to demonstrate the simplicity of very-basic shell scripting (assuming, as above, that /bin/bash is your shell), try the following at your command line:host # echo hi
hi
host # echo "echo hi" >>newscript
host # /bin/bash newscript
hi
Nice work :)
Cheers,
, Mike
Please note that this blog accepts comments via email only . See our Mission And Policy Statement for further details.
Tuesday, April 7, 2009
Duplicating And Modifying NetBackup Policies, Schedules And Client Via Command Line On Linux And Unix
Hey There,
SPOILER ALERT: THE BULLET POINTS IN THIS POST ARE IN ALL CAPS. I'M SORRY FOR SHOUTING. I HAVE NO SENSE OF HOW OBNOXIOUSLY LOUD I AM!
Actually tomorrow's post has turned into today's and I'm going to do today's tomorrow. I don't know why I felt compelled to write that. I guess I just don't want you to lose track of time like I do ;)
Today we're going to check out a way to copy (and modify) an existing host's NetBackup policies, clients and schedules to a new host, and then modify those policies, clients and schedules (just slightly) to suit the new host (you can't backup to a hostname that isn't the name of the host you want to back up. ...if you want to backup your the new host, that is ;)
The beauty of it is that it can all be done from the command line. No more UI GUI for you :)
And now, in one of my driest pieces to date, a step by step guide on how to perform the process I just described above (If you're interested in staying away from the GUI, check out our old post on our NetBackup command line activity monitor )
1. GET YOUR POLICIES AND SCHEDULES FROM THE KNOWN-GOOD HOST YOU WANT TO EMULATE/REPLICATE (orig_host will be the known-good host and new_host will be the host you want to be just about the same. Also, we're assuming you've installed the base product. This walk-through is focused only on policies, policy schedules and policy clients).
orig_host # ls /usr/openv/netbackup/db/class (you may have more than this - generally there's one directory per policy. Each directory includes the schedules for the policy the directory name indicates):HOST_BACKUP HOST_OS_BACKUP HOST_CATALOG
You may want to copy off the old policy and schedule output, just so you can compare it with your new host setup later and make sure you didn't forget to change any instances of an old hostname to your new hostnameorig_host # /usr/openv/netbackup/bin/admincmd/bppllist -allpolicies -U >/var/tmp/policies.txt
Then just tar that all up:orig_host # tar cpf /var/tmp/policies_and_schedules.tar /usr/openv/netbackup/db/class /var/tmp/policies.txt
2. VERIFY THAT EITHER NO "class" DIRECTORY EXISTS ON YOUR NEW HOST, THE EXISTING "class" DIRECTORY IS EMPTY OR THAT IT JUST CONTAINS THE STANDARD TEST GARBAGE YOUR SETUP MAY COME WITH - DELETE IT OR UNTAR OVER IT IF YOU WANT TO (USER DISCRETION ADVISED!) - THIS MAY NOT BE A BIG DEAL SINCE YOU PROBABLY HAVE NO SCHEDULES OR POLICIES ON YOUR NEW HOST ANYWAY.new_host # ls /usr/openv/netbackup/db
/usr/openv/netbackup/db: No such file or directory
new_host # ls /usr/openv/netbackp/db/class
/usr/openv/netbackp/db/class: No such file or directory
new_host # ls /usr/openv/netbackp/db
/usr/openv/netbackp/db: No such file or directory
3. AFTER SCP'ING/COPYING THE TAR FILE FROM YOUR KNOWN GOOD HOST, UNTAR IT ON THE NEW HOST AND LIST ALL POLICIES TO DOUBLE VERIFY - THE HOST NAMES WILL BE WRONG (FOR YOUR NEW HOST) SO THE DIFF WON'T BE TOO DIFFERENT!new_host # tar xpf /var/tmp/policies_and_schedules.tar
new_host # /usr/openv/netbackup/bin/admincmd/bppllist -allpolicies -U >/var/tmp/policies_new.txt
diff /var/tmp/policies.txt /var/tmp/policies_new.txt
4. CHECK THAT ALL THE POLICIES ARE THERE IN YOUR policies_new.txt FILE (YOU CAN LOOK IN BPADM, TOO). ALL HOSTNAMES AND TAPE RESIDENCE NAMES WILL STILL BE WRONG (ANYTHING THAT CONTAINS A HOSTNAME, ANYWAY)new_host # /usr/openv/netbackup/bin/admincmd/bppllist -M new_host
HOST_BACKUP
HOST_OS_BACKUP
HOST_CATALOG
5. DETERMINE YOUR TAPE RESIDENCE (TLD NAME) ON THE NEW HOST (FIRST ENTRY IN OUTPUT BELOW)new_host # /usr/openv/netbackup/bin/admincmd/bpstulist
new_host-hcart3-robot-tld-o 2 new_host 8 0 20 2 0 "*NULL*" 0 1 1048576 *NULL* 0 1 0 0 0 0 *NULL* new_host
"new_host-hcart3-robot-tld-o" is the residence name
6. ASSUMING ALL POLICIES LISTED ABOVE ARE GOOD, YOU WON'T HAVE TO MODIFY THIS LINE TO REMOVE AND/OR UPDATE THE RESIDENCE FOR ALL POLICIES (OF COURSE, THEY PROBABLY AREN'T SINCE THIS POST WAS WRITTEN FOR THE GENERAL PUBLIC ;)new_host # while read line;do /usr/openv/netbackup/bin/admincmd/bpplinfo $line -modify -residence new_host-hcart3-robot-tld-o;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host`"
7. LIST OUT ALL THE SCHEDULES NOW - NOTE THAT YOU MAY NOT WANT TO MODIFY YOUR CATALOG POLICY AND THAT SOME POLICIES HAVE MORE THAN ONE CLIENT (This may vary from setup to setup, so it's important to check!)
NOTE ALSO THAT, SINCE YOU'RE NOT CHANGING YOUR SCHEDULES, ALL YOU NEED TO DO TO MODIFY THEM IS TO CHANGE THE CLIENTS ASSOCIATED WITH THEM, WHICH GETS DONE IN THE FOLLOWING STEPS, AS WELL :)new_host # while read line;do echo "POLICY $line";/usr/openv/netbackup/bin/admincmd/bpplclients $line;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host`"
POLICY HOST_BACKUP
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 orig_host
POLICY HOST_OS_BACKUP
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 orig_host
Solaris Solaris10 orig_host2
POLICY HOST_CATALOG
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris8 orig_host
8. WITH THE SAME ASSUMPTIONS AS ABOVE, USE THIS TO CHANGE CLIENTS FOR YOUR POLICIES - CHOPPING OFF LAST POLICY AND MODIFIYING CLIENTS BY TAKING INPUT FROM LIST, MODIFYING AND THEN RUNNING "ADD NEW" AND "DELETE OLD" IN A LOOP (The simple sed expression to change the host name can be as specific as you like)
A. DO A "PROOF OF CONCEPT" RUN FIRSTwhile read line;do count=3;for x in $(/usr/openv/netbackup/bin/admincmd/bpplclients $line|awk '{print 3ドル}'|grep db|/usr/bin/sed 's/orig_/new_/g'|xargs echo);do oldhwos=$(/usr/openv/netbackup/bin/admincmd/bpplclients $line|sed -n ${count}p|awk '{print 1,ドル2ドル}');let count=$count+1;echo "POC TEST $line /usr/openv/netbackup/bin/admincmd/bpplclients $line -add $x $oldhwos";done;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host|egrep -iv 'vault|catalog'`"
POC TEST HOST_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_BACKUP -add new_host Solaris Solaris10
POC TEST HOST_OS_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -add new_host Solaris Solaris10
POC TEST HOST_OS_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -add new_host2 Solaris Solaris10
B. THEN - IF ALL IS WELL - DO IT FOR REALwhile read line;do count=3;for x in $(/usr/openv/netbackup/bin/admincmd/bpplclients $line|awk '{print 3ドル}'|grep db|/usr/bin/sed 's/orig_/new_/g'|xargs echo);do oldhwos=$(/usr/openv/netbackup/bin/admincmd/bpplclients $line|sed -n ${count}p|awk '{print 1,ドル2ドル}');let count=$count+1;echo "Running /usr/openv/netbackup/bin/admincmd/bpplclients $line -add $x $oldhwos";/usr/openv/netbackup/bin/admincmd/bpplclients $line -add $x $oldhwos;done;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host|egrep -iv 'vault|catalog'`"
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_BACKUP -add new_host Solaris Solaris10
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -add new_host Solaris Solaris10
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -add new_host Solaris Solaris10
C. CHECK TO MAKE SURE THE NEW CLIENTS ARE ADDEDwhile read line;do /usr/openv/netbackup/bin/admincmd/bpplclients $line ;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host`"
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 orig_host
Solaris Solaris10 new_host
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 orig_host
Solaris Solaris10 orig_host1
Solaris Solaris10 new_host
Solaris Solaris10 new_host1
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris8 orig_host
Solaris Solaris8 new_host
D. NOW SOME POC TO MAKE SURE THE DELETE OF THE OLD HOSTS WORKS OKAYwhile read line;do for x in $(/usr/openv/netbackup/bin/admincmd/bpplclients $line|awk '{print 3ドル}'|grep orig_|xargs echo);do echo "POC TEST $line /usr/openv/netbackup/bin/admincmd/bpplclients $line -delete $x";done;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host|egrep -iv 'vault|catalog'`"
POC TEST HOST_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_BACKUP -delete orig_host
POC TEST HOST_OS_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -delete orig_host
POC TEST HOST_OS_BACKUP /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -delete orig_host1
E. THEN REMOVE THEM FOR REALwhile read line;do for x in $(/usr/openv/netbackup/bin/admincmd/bpplclients $line|awk '{print 3ドル}'|grep orig_|xargs echo);do echo "Running /usr/openv/netbackup/bin/admincmd/bpplclients $line -delete $x";/usr/openv/netbackup/bin/admincmd/bpplclients $line -delete $x;done;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host|egrep -iv 'vault|catalog'`"
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_BACKUP -delete orig_host
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -delete orig_host
Running /usr/openv/netbackup/bin/admincmd/bpplclients HOST_OS_BACKUP -delete orig_host1
F. THEN CHECK AGAINwhile read line;do /usr/openv/netbackup/bin/admincmd/bpplclients $line ;done <<< "`/usr/openv/netbackup/bin/admincmd/bppllist -M new_host`"
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 new_host
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris10 new_host
Solaris Solaris10 new_host1
Hardware OS Client
--------------- --------------- --------------
Solaris Solaris8 orig_host
9. NOW THAT YOU'VE GOT THE POLICIES, SCHEDULES AND CLIENTS MOVED OVER, MAKE SURE THAT YOUR CATALOG JOB EXISTS (IF YOU USE ONE)new_host # /usr/openv/netbackup/bin/admincmd/bppllist HOST_CATALOG
CLASS HOST_CATALOG *NULL* 0 650000 0 *NULL*
NAMES
INFO 35 1 0 0 *NULL* 0 0 1 1 0 1 2 0 0 0 0 0 0 1236208342 EA91EDF01DD111B2AB1900144FEAC8FE 1 0 0 0 0 0 0 0 2 0 0 0 0 0 6
KEY *NULL*
BCMD *NULL*
RCMD *NULL*
RES new_host-hcart3-robot-tld-o *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL* *NULL*
POOL CATALOGPOOL NetBackup NetBackup NetBackup NetBackup NetBackup NetBackup NetBackup NetBackup NetBackup
FOE 0 0 0 0 0 0 0 0 0 0
SHAREGROUP *ANY*
DATACLASSIFICATION *NULL*
CLIENT new_host Solaris Solaris8 0 0 0 0 *NULL*
INCLUDE CATALOG_DRIVEN_BACKUP
10. NOW JUST DEACTIVE ANY POLICIES THAT ARE ACTIVE AND SHOULDN'T BE AND ACTIVATE ANY POLICIES THAT SHOULD BE ACTIVE BUT AREN'T!
All set!
CHEERS! ;)
, Mike
Please note that this blog accepts comments via email only . See our Mission And Policy Statement for further details.