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
$ 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:
Please use [CODE] tags when posting source listings, ...
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)
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)
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)
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)
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)
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)
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)
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)
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)
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)