05-28-2012 08:27 AM
Hi Dudes,
I have made a script to chk the media availability
Solved! Go to Solution.
05-29-2012 06:54 AM
functionality to this script, but I feel that the amount of work involved just to run "as is" is minimal & acceptable from an administrative point of view.
If someone told me that to get the information that I required involved editting a file by pasting in a bunch of numbers & then running a script then I would say "Fine. No problem". I *still* feel that this method is as 'long-winded' as being told I needed to run the script then at a particular point I would need to paste in my list of numbers in order to get the information.
In all honesty I cannot see the advantage of pursuing any further options to make this a one-button functionality for what you are likely to gain in the long run - but that's just my point of view.
05-28-2012 08:55 AM
What you need to do is test for the existance of the media first then depending on the condition '$?' determine if you should run the nbemmcmd command for that media.
What are exactly are you trying to do?
There is a available_media script in /usr/openv/netbackup/bin/goodies/
05-28-2012 09:27 AM
Hi Dude revaroo
Thanks for the quick reply
Usually to perform restore we will check wether the media is onsite or offsite to recall it. Usually
i will use nbemmcmd -listmedia -mediaid <mediaid> | egrep 'Last Write Host|Robot Number|Date Vaulted'
now i want to check a n numbers of tapes say 10 tapes in one command
so i created this script
Could you please help me on this.
05-28-2012 09:48 AM
ok test for the existence of the tape in the robot, if it is in the robot, run the nbemmcmd command. If it is not, run an exit 1
05-28-2012 10:27 AM
Dude
getting the below err
05-28-2012 10:38 AM
Try this, done from the top of my head so may or may not work. Would be best to put the contents into a variable, but for sheer simplicity, running nbemmcmd twice does not use up barely any resources considering you are unlikely to be using more than a few tapes
05-28-2012 10:39 AM
I missed a closing ' on the INROBOT line - now corrected.
05-28-2012 11:31 AM
Dude again getting the same err
05-28-2012 11:40 AM
This line is incorrect
You have a " at the end not a ' followed by a ` so should be
INROBOT=`nbemmcmd -listmedia -mediaid $a | awk -F: '/Robot Number/ {print $2}'`
05-28-2012 09:35 PM
Thanks Dude
Now th o/p is ending
05-29-2012 12:57 AM
The main issue(s):
- if the first tape is not in a library then if the script worked it would finish before reading further mediaids
--> removed the exit statement
- the error is always appearing as essentially you are hitting <CR> to finish input of mediaids & so feeding NULL into the nbemmcmd.
--> changed input method to space separated list of mediaids.
- output potentially confusing
--> 'echo'ed mediaid with output.
- 'strange' formatting for value of $INROBOT caused issues with 'if' statement
--> echoed one variable $ROBOT to another to strip out spaces (best I could do at the time!)
#!/bin/ksh
echo "Dude enter list of media id's to check separated by spaces"
read list
for a in $list
do
echo "\n$a"
ROBOT=`nbemmcmd -listmedia -mediaid $a | awk -F: '/Robot Number/ {print $2}'`
INROBOT=`echo $ROBOT`
if [ "$INROBOT" = "-" ]
then
echo "$a is not located in a robot"
else
nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
fi
done
***bolded text should be amended - see second edit below
Example of output:
Dude enter list of media id's to check separated by spaces 300259 300948 300210 300259 Last Write Host: blahblahblah Robot Number: 1 Date Vaulted: - 300948 300948 is not located in a robot 300210 Last Write Host: NONE Robot Number: 1 Date Vaulted: -
***EDIT***
Have remove the formatting for the script in this post as it stripped off some of the text - thank you Connect formatting!
However, looking at what's been printed out the "Date vaulted" is a little moot as no info is printed for media in the robot & there's no output for media not in the robot.
Will need to re-jig the script to print output for those media not in robot so that you get info for those media.
Sorry, I focussed on the later amendments to your script & not your actual requirements.....DOH!
***EDIT #2***
To get usable output for ALL media, change the last bit of the script to read:
if [ "$INROBOT" = "-" ]
then
echo "$a is not located in a robot"
fi
nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
before the 'done' statement at the very end. So this essentially just emphasises the fact that it's not in the robot with the statement "... is not located in a robot", but you could've got that info anyway just by looking at the 'value' against "Robot Number" - all that work for not a lot ;)
05-29-2012 01:27 AM
Instead of just following blindly what others have suggested?
Just make the following change (already mentioned above thankfully!) to your original script:
#!/bin/ksh
echo "Dude enter list of media id's to check separated by spaces"
read list
for a in $list
do
echo "\n$a"
nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
done
& you get the output you originally wanted & no 'error' message.
05-29-2012 01:51 AM
Thanks Andy, I don't have access to a system currenrtly so was unable to see the intended output, but I knew it was along the right lines. I did think he wanted to exit checking for tapes if any one tapes was not found in the robot "I want to stop chking mediaids if there is no media id " - assumed this to be stop checking full stop if a media id is not there.
05-29-2012 01:58 AM
for some reason, followed your lead but started to have issues with what the script was doing & "got lost in the moment".
It was only when I sat back having got it to 'work' & then thought "Where's the logic in that?" that I re-read the OP.
Seems like we could've got there in the end tho', but that remains to be seen....
05-29-2012 04:02 AM
Hi Andy & Revaroo,
Thank u verymuch for your help now it is working.
But i have one consern. I want to copy all the media ids and paste to feed the i/p. Here i have to copy paste the media ids one by one with space. So if i want to check more than 10 tapes at a time then i will suck our time of pasting one by one.
Could you please help me on this.
one Humbe request suggest some good PDFs for scripting. I am new to this.
Thanks & Regards
Gopinath S
05-29-2012 04:18 AM
Paste the list in a text file, e.g. /tmp/tapes, then read contents in 'for' loop:
for a in `cat /tmp/tapes`
do
......
05-29-2012 04:20 AM
e.g.
contents of file "tape.lst"
300948
300250
300259
then change your script to:
cat tape.lst|
while read a
do
echo "\n$a"
nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
done
Unfortunately you don't get your quote "Dude enter list of media id's to check separated by spaces"!!
You just need to amend the contents of your tape list file & run the script.
***EDIT***
ninja'd by Ms MvdB!
If you find a pdf for scripting let me know - those that know their stuff'll tell you that I make it up as I go along!
05-29-2012 04:27 AM
Thanks for your help!!
But i want to chk the medias status with script it self. If i am pasting the media ids in another file and calling the file in the script also time consuming. Is there a possible ways that in script it self i have to get the o/p for bulk ids.
Thanks & Regards,
Gopinath S
05-29-2012 04:32 AM
Oops Hi Andy Just seen ur command,
Could you please help me on this.
i need it should be
05-29-2012 04:35 AM
Is it possible to redirect the pasted ids to some temp memory as a file and ask the script to chk in the script it self