convert PERL script to SHELL script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting convert PERL script to SHELL script
# 1  
Old 12-09-2008
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  
Old 12-10-2008
Please help guys.
# 3  
Old 12-10-2008
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  
Old 12-11-2008
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  
Old 12-11-2008
Thanks all of you guys for your times and effort. God bless you all
# 6  
Old 12-12-2008
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  
Old 12-12-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Can someone convert this python script to perl

There is a python script that I would like converted to a perl script. If someone has the time to convert the script I would appreciate it. You can find the script below: reboot-mb8600/reboot-mb8600.py at master . j4m3z0r/reboot-mb8600 . GitHub #!/usr/bin/python ''' A hacky script to... (1 Reply)
Discussion started by: azdps
1 Replies

2. Shell Programming and Scripting

Kindly help me out to convert this script to shell script.

set +v echo "Program Name :" $0 # echo "Next param :" $1 echo "Next param :" "Username/Password" echo "User Id :" $2 echo "User Name :" $3 echo "Request ID :" $4 echo "Original File Name ... (4 Replies)
Discussion started by: Ganesh1985
4 Replies

3. Shell Programming and Scripting

Convert shell script to Perl

Hello,,I have a very small script that contains these lines; and it works perfectly; however I need to use Perl now as I will need to feel variables from a MySQL table into this; to it would be nice to start by converting this first... find / -perm 777 \( -type f -o -type d \) -exec ls -lid {}... (1 Reply)
Discussion started by: gvolpini
1 Replies

4. Shell Programming and Scripting

HELP on Perl array / sorting - trying to convert Korn Shell Script to Perl

Hi all, Not sure if this should be in the programming forum, but I believe it will get more response under the Shell Programming and Scripting FORUM. Am trying to write a customized df script in Perl and need some help with regards to using arrays and file handlers. At the moment am... (3 Replies)
Discussion started by: newbie_01
3 Replies

5. Shell Programming and Scripting

Help: how to convert perl script to shell script

bash$ mdb-schema x.mdb | perl -wpe 's%^DROP TABLE %DROP TABLE IF EXISTS %i; s%(Memo/Hyperlink|DateTime( \(Short\))?)%TEXT%i; s%(Boolean|Byte|Byte|Numeric|Replication ID|(\w+ )?Integer)%INTEGER%i; s%(BINARY|OLE|Unknown (+)?)%BLOB%i; s%\s*\(\d+\)\s*(,?*)$%${1}%;' | sqlite3 x.db ... (1 Reply)
Discussion started by: jackpapa
1 Replies

6. Shell Programming and Scripting

how to convert a shell script to a php script for displaying next word after pattern match

I have a shell script which I made with the help of this forum #!/bin/sh RuleNum=$1 cat bw_rules | sed 's/^.*-x //' | awk -v var=$RuleNum '$1==var {for(i=1;i<=NF;i++) {if($i=="-bwout") print $(i+3),$(i+1)}}' Basically I have a pages after pages of bandwidth rules and the script gives... (0 Replies)
Discussion started by: sb245
0 Replies

7. Shell Programming and Scripting

convert perl code to shell script

This is about how to Monitoring folder for new files using shell script im doing a project using smsserver tools 3. i have used a perl script to handle incoming messages. the content of each message must be directed to a java program. this program generates the answer to reply to the user... (2 Replies)
Discussion started by: x34
2 Replies

8. Shell Programming and Scripting

Convert .sh script into perl

Good afternoon to you all I really need your help I have the following script developed in .sh and I need to convert it into perl. Can someone help me do it please? Here´s the script: ############################################## ############################################## ... (3 Replies)
Discussion started by: zarahel
3 Replies

9. Shell Programming and Scripting

Shell/Perl script to convert to Capitalize case

I need a shell script which will convert the given string within a <title> tag to Capitalize case. E.g "<title>hi man: check this out</title>" to "<title>Hi Man: Check This Out</title>" (11 Replies)
Discussion started by: parshant_bvcoe
11 Replies

10. Shell Programming and Scripting

convert the below perl sript to shell script

perl script: my $logdir = '/smp/dyn/logfiles/fsm/mp/mp'; $logdir = $logdir ."/mp${toDate}*"; i tried to make it..as below .. but not working .. date +%m%d%y logdir = /smp/dyn/logfiles/fsm/mp/mp logdir=$logdir/mp"$date" but it was not working..... can someone please help me out in... (1 Reply)
Discussion started by: mail2sant
1 Replies
Login or Register to Ask a Question