cancel
Showing results for 
Search instead for 
Did you mean: 

script to check the media availability

Gopinathsethu
Level 4

Hi Dudes,

 

I have made a script to chk the media availability

 

 

#!/bin/ksh
 
echo "Dude enter the media id's to check"
 
while read a
 
do
 
echo "\n"
 
nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
 
done
 
###############################################################################################################
 
The o/p of above script is the below.
 
Dude enter the media id's to check
L18139
L19979
L20000
 
Last Write Host:                reuxeuus653
Robot Number:                   -
Date Vaulted:                   05/21/2012 10:50
L19979
 
 
Last Write Host:                reuxeuus653
Robot Number:                   8
Date Vaulted:                   -
L20000
 
 
Last Write Host:                reuxeuus653
Robot Number:                   -
Date Vaulted:                   05/21/2012 10:50
 
 
 
The value for this option was missing:
mediaid
Usage:
nbemmcmd -listmedia  [-allrecords] [-brief] [-conflicts] [-emmname <string>]
[-emmport <unsigned integer>] [-mediaid <string>] [-mediatype <unsigned integer>]
[-mergetable] [-poolname <string>] [-robotnumber <unsigned integer>]
[-vaultcontainer <string>]
^C
 
$$$########################################################################
 
 I want to stop  chking mediaids if there is no media id . and if possible please trim the script better ways
 
Thanks & Regards
 
Gopinath S

 

1 ACCEPTED SOLUTION

Accepted Solutions

Andy_Welburn
Level 6

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.

View solution in original post

35 REPLIES 35

revarooo
Level 6
Employee

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/

 

Gopinathsethu
Level 4

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.

 

 

revarooo
Level 6
Employee

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

 

 

Gopinathsethu
Level 4

Dude

getting the below err

 

 

root:reuxeuus474# ./mediacheck.sh
Dude enter the media id's to check
./mediacheck.sh[5]: syntax error at line 11 : ``' unmatched
root:reuxeuus474#
 
 

revarooo
Level 6
Employee

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

 

 

#!/bin/ksh
 
echo "Dude enter the media id's to check"
 
while read a
 
do
 
echo "\n"
 
INROBOT=`nbemmcmd -listmedia -mediaid $a | awk -F: '/Robot Number/ {print $2}'`
 if [ -z "$INROBOT" ] 
  then
   echo "$a is not located in a robot, exiting" 
   exit 
  else
  nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
 fi
done

revarooo
Level 6
Employee

I missed a closing ' on the INROBOT line - now corrected.

Gopinathsethu
Level 4

Dude again getting the same err

 

 

root:reuxeuus474# vi mediacheck.sh
 
 
 
 
 
 
 
 
 
 
 
"mediacheck.sh" 19 lines, 358 characters
#!/bin/ksh
 
echo "Dude enter the media id's to check"
 
while read a
 
do
 
echo "\n"
 
INROBOT=`nbemmcmd -listmedia -mediaid $a | awk -F: '/Robot Number/ {print $2}''
 if [ -z "$INROBOT" ]
  then
   echo "$a is not located in a robot, exiting"
   exit
  else
  nbemmcmd -listmedia -mediaid $a | egrep 'Last Write Host|Robot Number|Date Vaulted'
 fi
done
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
~
"mediacheck.sh" 19 lines, 359 characters
root:reuxeuus474# ./mediacheck.sh
Dude enter the media id's to check
./mediacheck.sh[5]: syntax error at line 11 : ``' unmatched
root:reuxeuus474#
 

revarooo
Level 6
Employee

This line is incorrect

INROBOT=`nbemmcmd -listmedia -mediaid $a | awk -F: '/Robot Number/ {print $2}''

 

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}'`

 

Gopinathsethu
Level 4

Thanks Dude

Now th o/p is ending

 

root:reuxeuus474# ./mediacheck.sh
Dude enter the media id's to check
L18139
L19979
L20000
 
Last Write Host:                reuxeuus653
Robot Number:                   -
Date Vaulted:                   05/21/2012 10:50
L19979
 
 
Last Write Host:                reuxeuus653
Robot Number:                   8
Date Vaulted:                   -
L20000
 
 
Last Write Host:                reuxeuus653
Robot Number:                   -
Date Vaulted:                   05/21/2012 10:50
 
 
 
The value for this option was missing:
mediaid
Usage:
nbemmcmd -listmedia  [-allrecords] [-brief] [-conflicts] [-emmname <string>]
[-emmport <unsigned integer>] [-mediaid <string>] [-mediatype <unsigned integer>]
[-mergetable] [-poolname <string>] [-robotnumber <unsigned integer>]
[-vaultcontainer <string>]
 is not located in a robot, exiting
 
but still i am getting 
 
The value for this option was missing:
mediaid
Usage:
nbemmcmd -listmedia  [-allrecords] [-brief] [-conflicts] [-emmname <string>]
[-emmport <unsigned integer>] [-mediaid <string>] [-mediatype <unsigned integer>]
[-mergetable] [-poolname <string>] [-robotnumber <unsigned integer>]
[-vaultcontainer <string>]
 is not located in a robot, exiting
 
 
 
Could you please check it.
 
Thanks & Regards 
 
Gopinath
 
if u have skype id please ping me i will share my screen
 
 

Andy_Welburn
Level 6

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 ;)

Andy_Welburn
Level 6

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.

revarooo
Level 6
Employee

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.

Andy_Welburn
Level 6

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

Gopinathsethu
Level 4

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

Marianne
Moderator
Moderator
Partner    VIP    Accredited Certified

Paste the list in a text file, e.g. /tmp/tapes, then read contents in 'for' loop:

for a in `cat /tmp/tapes`

do

......

 

Andy_Welburn
Level 6

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!

Gopinathsethu
Level 4

Hi Marianne van den Berg

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

Gopinathsethu
Level 4

Oops Hi Andy Just seen ur command,

 

Could you please help me on this.

i need it should be

 

 

Dude enter list of media id's to check
 
L19979
L20000
L19979
 
then the script has to chk
 
Thanks & Regards
Gopinath S

Gopinathsethu
Level 4

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