Sponsored Content
Top Forums Shell Programming and Scripting Cannot execute Unix command in a simple perl script Post 302558443 by jayachandran87 on Friday 23rd of September 2011 02:27:32 PM
Old 09-23-2011
Question Cannot execute Unix command in a simple perl script

Am trying to lean perl scripting in Unix OS to automate my tasks.

Please find the below perl script i have tried


Code:
#!/usr/bin/perl -w
print "Please Enter the VG name to be checked:";
$A = <>;
print "Please Enter the free size to be checked in GB:";
$B = <>;
        $vgcheck = `vgdisplay -v 2> /dev/null |grep -i "vg name" |grep -i $A`;
        $vgcheckc = `echo "$vgcheck" |wc -c`;
        print "$vgcheckc";
        if ($vgcheckc > 0)
                {
                $FREE = `vgdisplay $A | grep -i 'Free PE' | awk '{print $NF}'`;
                print $FREE;
                $PESIZE = `vgdisplay $A |grep -i 'PE Size' |awk '{print $NF}'`;
                print $PESIZE
                $total = $FREE * $PESIZE;
                $check = $B * 1024;
                        if ($total > $check)
                        {
                        print "Required Free Space is there in VG $A.. Please proceed to extend the Filesystem as requested\n";
                        print "TOtal free Space in VG $A is : $total MB";
                        }
                        else
                        {
                        print "Required Free Space is NOT there in VG $A..New LUNS are needed. CR must be raised \n";
                        print "Total free Space in VG $A is : $total MB\n";
                        $diff = $check - $total;
                        print "$diff MB of lun must be added to vg $A to proceed with Filesystem Extension\n";
                        }
                }
        else
                {
                print "Please give the correct VG name. The given VG is either not present nor It is NOT Activated\n";


I want to get the "free pe" and "pe size" from the vgdisplay command. but the whole vgdisplay command O/P is being stored to the variable

Code:
$FREE = `vgdisplay $A | grep -i 'Free PE' | awk '{print $NF}'`;

O/P of the perl program

Code:
$ perl testperl.pl
Please Enter the VG name to be checked:vgesar
Please Enter the free size to be checked in GB:20
41
Use of uninitialized value in concatenation (.) or string at testperl.pl line 11, <> line 2.
sh[2]: Syntax error at line 2 : `|' is not expected.
--- Volume groups ---
VG Name                     /dev/vgesar
VG Write Access             read/write
VG Status                   available, exclusive
Max LV                      255
Cur LV                      1
Open LV                     1
Max PV                      100
Cur PV                      2
Act PV                      2
Max PE per PV               1599
VGDA                        4
PE Size (Mbytes)            32
Total PE                    3198
Alloc PE                    3129
Free PE                     69
Total PVG                   0
Total Spare PVs             0
Total Spare PVs in use      0

Use of uninitialized value in concatenation (.) or string at testperl.pl line 13, <> line 2.
sh[2]: Syntax error at line 2 : `|' is not expected.
Argument "--- Volume groups ---\nVG Name                     /dev/..." isn't numeric in multiplication (*) at testperl.pl line 14, <> line 2.
Argument "--- Volume groups ---\nVG Name                     /dev/..." isn't numeric in multiplication (*) at testperl.pl line 14, <> line 2.

Moderator's Comments:
Mod Comment Please use [CODE] tags when posting source listings, ...

Last edited by pludi; 09-23-2011 at 03:51 PM..
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Net::SSH::Perl->Execute any unix command & display the output in a proper form

Net::SSH::Perl ...... how to print the output in a proper format my $cmd = "ls -l"; my $ssh = Net::SSH::Perl->new($host); $ssh->login($user, $pass); my($stdout, $stderr, $exit) = $ssh->cmd("$cmd"); print $stdout; the script works fine, but i am unable to see the output... (2 Replies)
Discussion started by: gsprasanna
2 Replies

2. Shell Programming and Scripting

Execute in unix not in PERL

Hi All, This below command is working fine with unix box. However i could not able to run it in PERL. kidly suggest??? perl -ne '{push @x, $_}END{pop(@x); print @x}' create2.txt (15 Replies)
Discussion started by: adaleru
15 Replies

3. Shell Programming and Scripting

perl/unix: script in command line works but not in perl

so in unix this command works works and shows me a list of directories find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt but when i try running a perl script to run this command my $query = 'find . -name \*.xls -exec dirname {} \; | sort -u | > list.txt';... (2 Replies)
Discussion started by: kpddong
2 Replies

4. Shell Programming and Scripting

how to execute ksh simple shell script without creating .sh file

please help me to execute a simple shell script like for i in `ls echo $i done . i dont want to create a new sh file to execute it. Can i just type and execute it ? because I always this kind of simple for loops . Please help . Thanks (7 Replies)
Discussion started by: Sooraj_Linux
7 Replies

5. Shell Programming and Scripting

Help making simple perl or bash script to create a simple matrix

Hello all! This is my first post and I'm very new to programming. I would like help creating a simple perl or bash script that I will be using in my work as a junior bioinformatician. Essentially, I would like to take a tab-delimted or .csv text with 3 columns and write them to a "3D" matrix: ... (16 Replies)
Discussion started by: torchij
16 Replies

6. Shell Programming and Scripting

execute ssh command via perl

Hi I have a perl command that doesn't seem to be working correctly. It appears to be fine but even when i try and run it manually same thing. Can someone take a look at this and tell me what they think the problem could be? Here is the perl Line: system ("echo 'ssh -t -t $user\@$_ \"cd... (3 Replies)
Discussion started by: vpundit
3 Replies

7. UNIX for Dummies Questions & Answers

Execute a command in different directory through Unix Script

Hi Gurus, I have the below requirement, Execute an unix script which will pick the latest file from the archive directory and do a grep (on multiple patterns) on that file. processingDir="/usr/apps/irdc/informatica/spsf_sales/TgtFiles/ARCHIVE" filename = 'ls Check* | sort -n -k 2 |... (6 Replies)
Discussion started by: diva_thilak
6 Replies

8. Shell Programming and Scripting

Using UNIX command in perl script.

I wish to know if there is any limitation in using unix commands in perl script or it is just we should avoid using them in our perl script. For e.g Below is the command to get the recent file in a dir.: $lcsvFile = `cd "$l_inputfilepath";ls -1t *.CSV|tail -1` Is there any harm in coding... (1 Reply)
Discussion started by: Devesh5683
1 Replies

9. Linux

How to execute a simple select script using a shell script?

Hi team, I have two select statements and need to run them using SYSDBA user select * from temp_temp_seg_usage; select segment_name, tablespace_name, bytes/ (1024*1024) UsedMb from dba_segments where segment_name='TEMP_TEMP_SEG_USAGE'; Need to run this using a shell script say named... (1 Reply)
Discussion started by: pamsy78
1 Replies

10. 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
All times are GMT -4. The time now is 12:58 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy