Sponsored Content
Top Forums Shell Programming and Scripting Conversion of Perl Script to Shell Script.. Post 302927715 by Pawan Ramnani on Friday 5th of December 2014 01:12:17 AM
Old 12-05-2014
Conversion of Perl Script to Shell Script..

Hi Guys
I am having a perl script that fetches exclude list from a unix client and I trying it to convert it to shell script but I am having issues please help me...


Code:
#!/usr/bin/perl

use strict; 
use warnings; 
use Getopt::Std; 


# To turn on debuging (i.e. more information) specify -d on the command line 
our $opt_d = 0; 

# To get ONLY the version information specify -v on the command line 
our $opt_v = 0; 

getopts('dv'); 

our $debug = $opt_d; 

my $uname = `uname -n`; 
chomp $uname; 

# Desiginate where to write the in/exclude files (must be fully qualified path) 
our $PWD = $ENV{PWD}; 
our $output_dir = "$PWD/EI_${uname}"; 
if ( ! -d $output_dir ) { mkdir $output_dir } 


# Location of bp.... commands 
our $nbadmin = "/usr/openv/netbackup/bin/admincmd"; 

# Generate a list of policies 
our @policy_list = `$nbadmin/bppllist`; 

# Used the get output of the bpgetconfig command. Only need for debut purposes 
our @status = (); 


foreach my $policy (@policy_list) { 
chomp $policy; 

# Get the individual policy information 
my @policy = `$nbadmin/bppllist $policy -l`; 

# Extract the info line 
my @info = grep /^INFO /, @policy; 

# If the policy type is not standard, ignore 
if ( (split /\s+/, $info[0])[1] != 0 ) { next } 

# If the policy is inactive, ignore 
if ( (split /\s+/, $info[0])[11] != 0 ) { next } 

# Pull out the clients for this policy and then keep only the client names 
my @clients = grep /^CLIENT /, @policy; 
@clients = map { (split /\s+/, $_)[1]} @clients; 

# Pull out the schedules for this policy and then keep only the schedule names 
my @schedules = grep /^SCHED /,@policy; 
@schedules = map { (split /\s+/, $_)[1]} @schedules; 

# Now for each client 
foreach my $client (@clients) { 

if ($debug != 0) { print STDERR "$client $policy\n"; } 

# Be sure the client is at leas pingable otherewise the bpgetconfig command will take a long time to fail 
system("ping -c 1 -W 5 $client > /dev/null 2>&1"); 
if ($? != 0 ) { print STDERR "$client not pingable\n"; next } 

open VERSION, ">$output_dir/version.$client" or die "Couldn't open $output_dir/version.$client for output: $!\n"; 
print VERSION "============= Version Check of $client ===================\n"; 
print VERSION `bpgetconfig -t -A -g $client 2>&1`; 
print VERSION "============= End Version Check of $client ===================\n"; 
close VERSION; 

if ( ! $opt_v ) { 
# get, if any, the basic include and/or exclude files. (i.e. /usr/openv/netbackup/exclude_list or include_list) 
@status = `$nbadmin/bpgetconfig -e \"/$output_dir/exclude.$client.basic\" \"$client\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -exclude no policy failed with $?\n @status" } 
@status = `$nbadmin/bpgetconfig -i \"/$output_dir/include.$client.basic\" \"$client\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -include no policy failed with $?\n @status" } 

# get, if any, the policy include and/or exclude files. (i.e. /usr/openv/netbackup/exclude_list.policy or include_list.policy) 
@status = `$nbadmin/bpgetconfig -e \"/$output_dir/exclude.$policy.$client\" \"$client\" \"$policy\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -exclude policy only failed with $?\n @status" } 
@status = `$nbadmin/bpgetconfig -i \"/$output_dir/include.$policy.$client\" \"$client\" \"$policy\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -include policy only failed with $?\n @status" } 

# Now for each schedule in the policy (i.e. /usr/openv/netbackup/exclude.policy.schedule= 
foreach my $schedule (@schedules) { 
if ($debug != 0) { print STDERR "$client $policy $schedule\n"; } 
@status = `$nbadmin/bpgetconfig -e \"/$output_dir/exclude.$policy.$client.$schedule\" \"$client\" \"$policy\" \"$schedule\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -exclude with policy and schedule failed with $?\n @status" } 
@status = `$nbadmin/bpgetconfig -i \"/$output_dir/include.$policy.$client.$schedule\" \"$client\" \"$policy\" \"$schedule\" 2>&1`; 
if ($? != 0 && $debug != 0 ) { print STDERR "$client bpgetconfig -include with policy and schedule failed with $?\n @status" } 
} 
} 
} 

# If any of the bpgetconfigs work the ouput will be in the file name following the -e or -i 
} 

exit;

====================== End of code ========================

Last edited by Don Cragun; 12-05-2014 at 02:40 AM.. Reason: Add CODE tags.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Conversion of bash parsing script to perl?

I need help with a perl parsing script. I have some error logs on a windows machine that I need to parse from a text file, but I know nothing about perl. I usually run this bash script on my linux box and it does just what I need. How would I do the same thing with perl and port it to my windows... (2 Replies)
Discussion started by: cstovall
2 Replies

2. Shell Programming and Scripting

Help me with file conversion [Shell Script]

Hello Group, I request your help with a shell script for filter an ascii file (this is small piece of the file): 09/24/2009,00:00,1.0268,1.0268,1.0249,1.0250,518 09/24/2009,01:00,1.0251,1.0261,1.0249,1.0259,424 09/24/2009,02:00,1.0258,1.0272,1.0258,1.0269,372... (3 Replies)
Discussion started by: csierra
3 Replies

3. Shell Programming and Scripting

Encoding conversion in PERL script

I have oracle 9i database installed with UTF-8 Encoding. I want a perl script that converts unicode to utf8 before commiting in database and utf8 to unicode when retreiving from database For example : the word Ïntêrnatïônàlîzâtion has to be stored in database as Internationalization and when retreived... (6 Replies)
Discussion started by: vkca
6 Replies

4. AIX

Need timestamp conversion shell script !!

Can anyone provide me with a ksh or bash script which will accept a timestamp (format is YYYY-MM-DD-HH24.Mi.Ss) and time offset (in hours). The output will be (timestamp passed - time offset passed deducted from it) in the same YYYY-MM-DD-HH24.Mi.Ss format. Basically I am trying to convert the... (1 Reply)
Discussion started by: shibajighosh
1 Replies

5. Shell Programming and Scripting

shell or perl script needed for ldif file to text file conversion

This is the ldf file dn: sdcsmsisdn=1000000049,sdcsDatabase=subscriberCache,dc=example,dc=com objectClass: sdcsSubscriber objectClass: top postalCode: 29600 sdcsServiceLevel: 10 sdcsCustomerType: 14 givenName: Adelia sdcsBlackListAll: FALSE sdcsOwnerType: T-Mobile sn: Actionteam... (1 Reply)
Discussion started by: LinuxFriend
1 Replies

6. Shell Programming and Scripting

Conversion batch shell script

while converting batch file to shell script ...dis command is ther i dunno how to change...can anyone knws how to change into shell script rm !(D:\temp\XX.txt) (3 Replies)
Discussion started by: monisha
3 Replies

7. Shell Programming and Scripting

Help required for Oracle database shutdown script conversion from shell to perl

Please tell me how to convert below program from shell script to perl. Same commands need to use in shutdown, just need program help for startup. export ORACLE_BASE=/home/oracle1 lsnrctl start lndb1 sqlplus '/ as sysdba' startup; (2 Replies)
Discussion started by: learnbash
2 Replies

8. Shell Programming and Scripting

Batch to shell script conversion

Hi All, I have a small tool which is currently configured in batch scripts only. But my need is to run it on Linux platform, so I have been trying to convert a batch script to shell script. below is the batch script: @echo off IF "%1"== "" GOTO ARGERR REM UPDATE THESE PROPERTIES TO... (2 Replies)
Discussion started by: sukhdip
2 Replies

9. UNIX for Beginners Questions & Answers

powershell script to unix shell script conversion.

Here is a powershell script to use restful API to create ticket in our ticketing tool. Can anyone please convert it to a shell script sothat, I can run it in Unix servers, below is the code: $body = @{ Customer= ''test' Summary= 'test summary' Impact= '4-Minor/Localized' ... (2 Replies)
Discussion started by: pandeybhavesh18
2 Replies

10. UNIX for Beginners Questions & Answers

Shell script ouput conversion

Hi All, I am trying to print all the packages info in solaris 11 using below script. #!/usr/bin/env bash pkginfo -l | egrep '(BASEDIR|NAME|VERSION)' | awk '{print}' > /tmp/cp1 /usr/bin/nawk -F: ' {for (i=1; i<=NF; i++) {gsub (/^ *| *$/, "", $i) ... (5 Replies)
Discussion started by: sravani25
5 Replies
All times are GMT -4. The time now is 05:13 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy