The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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
Call a perl script inside a shell script chriss_58 Shell Programming and Scripting 3 12-01-2008 04:28 AM
Need to convert ksh script to Perl rahimm1 Shell Programming and Scripting 1 10-21-2008 08:47 AM
Include PERL script with in the unix shell script ganapati UNIX for Dummies Questions & Answers 1 04-29-2008 12:18 PM
convert the below perl sript to shell script mail2sant Shell Programming and Scripting 1 04-04-2008 01:36 PM
convert unix script to perl gholdbhurg Shell Programming and Scripting 2 03-25-2008 01:42 PM

Closed Thread
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
  #1 (permalink)  
Old 12-09-2008
ma466 ma466 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 21
convert PERL script to SHELL script

Hi all experts,

I am new to Unix. Could you please help me to convert the following PERL script to SHELL? I will appreciate.

#!/bin/sh
use strict;
use warnings;
my $robot_num = 0;

my %rob_tapes;
foreach (`/usr/openv/volmgr/bin/vmquery -l -rn $robot_num`)
{ $rob_tapes{(split)[0]} = 1; }

foreach (`/usr/openv/netbackup/bin/admincmd/bpmedialist -l`)
{
my @line = split;
next unless exists $rob_tapes{$line[0]}; #remove for all
my $status = "";
if ($line[14] & 0x1 ) { $status .= " FROZEN"; }
if ($line[14] & 0x8 ) { $status .= " FULL"; }
if ($status) { print "$line[0] $status\n"; }
}
  #2 (permalink)  
Old 12-10-2008
ma466 ma466 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 21
Please help guys.
  #3 (permalink)  
Old 12-10-2008
Autocross.US's Avatar
Autocross.US Autocross.US is offline
Registered User
  
 

Join Date: Nov 2008
Location: Chesapeake, VA
Posts: 73
Perl to English Translation:

Looks like the script runs vmquery to put the Tape # (first column) into an array. The array values are later checked.

If a Tape # is found in the array, the number in the 15th column of output from the bpmedialist command for the tape # is bitwise checked to determine if the tape is frozen or full.

If the number has the binary 1 bit turned on, it is frozen
If the number has the binary 8 bit turned on, it is full
If the number has both bits turns on, it is full

The script loops through all found in array tape #'s and returns the status of full or frozen.

I could probably do this in shell, but i'm not that great with binary stuff. I'd use the perl script, as it it pretty quick and doesn't generate any temp files, which i think the shell script would have too. I may take a crack at this tomorrow if no solution has been posted.
  #4 (permalink)  
Old 12-11-2008
tderscheid tderscheid is offline
Registered User
  
 

Join Date: Apr 2008
Posts: 10
From PERL script to single line shell - "What's the status of my Netbackup Media?"

Heh. This took some sweating and cursing. Finally had to talk to the AWK guru in my office.

Code:
bpmedialist -l | awk '{print "echo `echo \"obase=2;"$15+4096"\" | bc` "$1}' | sh | cut -c10,13,14-99 | sort -n -n
This prints a list of media, sorted by Status code, then by Media ID, where 0 is available, 01 is Frozen, 10 is Full, and 11 is Full/Frozen. Took about 10 seconds to run for me, though I only have about 1800 tapes in the library.

I presume you're doing this so you can eject full and/or frozen tapes from your robot and load available tapes into the robot. You could put this in crontab and have it email to you right before you get to work every day, so you have an action plan for being the robot stableboy.

Curtis W. Preston has an excellent script out there called CLAM (Curtis' Library Automation Menu) that is an great place to look. It uses Perl but also includes easy "shove tapes into robot" and "extract tapes from robot" that is much faster than goofing with the GUI. We had to do minor tweaks to make it work with Netbackup 6.5.
  #5 (permalink)  
Old 12-11-2008
ma466 ma466 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 21
Thanks all of you guys for your times and effort. God bless you all
  #6 (permalink)  
Old 12-12-2008
ma466 ma466 is offline
Registered User
  
 

Join Date: Dec 2007
Posts: 21
Hi i could display only FULL/FROZEN ? I also want to have column which will show the status of the tape like

00 full
01 frozen
01 full

Now it only displays


# bpmedialist -l | awk '{print "echo `echo \"obase=2;"$15+4096"\" | bc` "$1}' | sh | cut -c10,13,14-99 | sort -n -n
00 000004
00 000005
00 000007
00 000009
00 000015
00 000018
00 000021
00 000023
00 000024
00 000025
00 000027
00 000028
00 000032
00 000039
01 000014
10 000001
10 000002
10 000008
10 000011
10 000013
10 000016
10 000017
10 000020
10 000022
10 000026
10 000030
10 000031
10 000034
10 000035
10 000037
10 000038
10 000040
#
Do i have to write if else statement withe the above shell so that when it is 10 it will display FULL and when it is 01 it will display frozen? Please give me some feedback.
  #7 (permalink)  
Old 12-12-2008
Autocross.US's Avatar
Autocross.US Autocross.US is offline
Registered User
  
 

Join Date: Nov 2008
Location: Chesapeake, VA
Posts: 73
Something like this:

Code:
bpmedialist -l | awk '{print "echo `echo \"obase=2;"$15+4096"\" | bc` "$1}' | sh | cut -c10,13,14-99 | sort -n -n | while read STATUS TAPE ; do

  case  $STATUS in
      00)  STATUS=??   ;;   
      01)  STATUS=??   ;;
      10)  STATUS=??   ;;
  esac
  print "$TAPE $STATUS"

done
Replace the question marks with the appropriate status.
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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 08:27 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