Variables in perl script


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Variables in perl script
# 1  
Old 10-08-2015
Variables in perl script

Hi Chaps,
Im after some advise with a script i've written however doesnt appear to work how I would like.

Basically I have a perl script which sucessfully pulls an expect script to login to multiple nodes and obtain some output from the nodes (total number of nat ports that are in use for the relivant pool on that node).

What I want to archieve is a list of the pools from each node with the number of ports in use, They if a single nat pool is using less than x number of ports to email me.

Firstly my perl script doesn't seem to output the details as I would like, for each pool i want the line to show the node name, then the port details (as per the below, what you will notice is in the output below the node name appears to be on the line above the port details) possibly due to control characters but not sure how is best to deal with this ?

Script:
Code:
#!/usr/bin/perl -w
use Term::ANSIColor;
use strict;
use constant DEBUG => 1;
my $pool0 = "";
my $pool1 = "";
my $filename = "list.txt";
open(my $fh, "<", $filename) or die "couldn't read file";
while (my $line = <$fh>){
        for (`../user/test2.sh $line`) {
                                if (/pool0\s\S+\s+\S+\s+\S+\s+(\S+)/) {
                                        $pool0 = $1;
                                print color("red"), "$line pool0 ports in use $pool0\n", color("reset");
                                }
                                if (/pool1\s\S+\s+\S+\s+\S+\s+(\S+)/) {
                                        $pool1 = $1;
                                print color("red"), "$line pool1 ports in use $pool1\n", color("reset");
                                }

                        }
}
exit 0;

Output with new lines between node name and value although I want it all in one line.

Code:
RN001
 pool0 ports in use 415963
RN001
 pool1 ports in use 425610
RB001
 pool1 ports in use 323477
RB001
 pool0 ports in use 325010

Also could anyone help in regards to how i can I check multiple nat pool values that the script puts into variables (pool0, pool1 etc) to send an email to me if any of them fall below a certain number of ports in us.

I want an email on a per node basis rather than per pool, It should only generate an email if it falls below the configured value.

Thanks for the help
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

2. Shell Programming and Scripting

Excuting perl script from within a perl script with variables.

Not sure what I am doing wrong here, but I can print the list with no issue. Just a blank screen with the 'do'. #!/usr/bin/perl open FILE, "upslist.txt"; while ($line=<FILE>){ if ($line=~/^(.*?),(.*?)$/){ #print "ups:$1 string:$2\n"; do 'check_snmp_mgeups-0.1.pl -H $1 -C $2'; } ... (1 Reply)
Discussion started by: mrlayance
1 Replies

3. Shell Programming and Scripting

Running a script with multiple variables like 25 variables.

Hi All, i have a requirement where i have to run a script with at least 25 arguements and position of arguements can also change. the unapropriate way is like below. can we achieve this in more good and precise way?? #!/bin/ksh ##script is sample.ksh age=$1 gender=$2 class=$3 . . .... (3 Replies)
Discussion started by: Lakshman_Gupta
3 Replies

4. Shell Programming and Scripting

Variables in perl

I don't fully understand variables in perl. If we have a variable defined like this "my $number = 1" then this is called a lexical variable? But if you define this at the top of a script then why isn't it a global variable because it would be available throughout the file? Sorry if this is... (1 Reply)
Discussion started by: P3rl
1 Replies

5. Shell Programming and Scripting

using variables in perl not working

sdcprd@dotstoas110:$ echo $F2 1327332411 this works ---------- sdcprd@dotstoas110:$ perl -MPOSIX -le 'print strftime ("%m%d%y",localtime (1327332411))' 012312 <<<< correct date this doesnt ----------- sdcprd@dotstoas110:$ perl -MPOSIX -le 'print strftime ("%m%d%y",localtime... (10 Replies)
Discussion started by: aliyesami
10 Replies

6. Shell Programming and Scripting

Use the same perl script with several different variables

I'm new to perl and have to create these files for my job. I have a script that I can run that will create the file, but I have to manually pass the variables to it. It is dumb and it takes a lot of time. I want to be able to pass the existing perl script a set of variables (the same variables... (4 Replies)
Discussion started by: smartin114
4 Replies

7. Shell Programming and Scripting

pass perl variables to shell script

I have a perl script that opens a text file containing numbers on each line: for example: 755993 755994 755995 755996 755997 755998 The perl script takes these numbers and store them as an array @raw_data, where I can access individual numbers by using $raw_data for the value 755993.... (2 Replies)
Discussion started by: xchen89x
2 Replies

8. Shell Programming and Scripting

Comparing Variables in Perl

Hi. I have three arrays. @a=('AB','CD','EF'); @b=('AB,'DG',HK'); @c=('DD','TT','MM'); I want to compare the elements of the first two array and if they match then so some substition. I tried using the if statement using the scalar value of the array but its not giving me any output. ... (7 Replies)
Discussion started by: kamitsin
7 Replies

9. Shell Programming and Scripting

Need help passing variables in shell script to perl one-liner

I'm writing a script to automate some post-install tasks on RHEL4 servers. I need the following code to insert an 'A' in the middle of a string, then replace the string in a file. I know I can use sed to do this, but I'd like to use perl's in place edit so I don't have to write to a temp file,... (1 Reply)
Discussion started by: Xek
1 Replies

10. Shell Programming and Scripting

accessing variables declared in another perl script

Hi all, I have a perl script which declares two variables and calls another perl script which accesses those variables. But I am unable to access the variables in the called script. My script is as follows: my $ENV{a}="20"; system("perl called.pl"); and my called.pl contains: print... (3 Replies)
Discussion started by: gurukottur
3 Replies
Login or Register to Ask a Question