Hi,
I need help with a loop in a script that is not doing what I want it to do. I include the whole script at the bottom of this message. The intention is that (1) it reads a file /var/opt/oratab into an array (this works), (2) It should go line by line, and separating the fields by : so that the 2nd one can be assigned to a variable with which I can run an OS command (per line) to check the permissions of bin files within each of these directories.
As it is now, the script prints the @lines array and then it is checking the permissions of the binary files ending in zero in $ORACLE_HOME/bin of the first oratab line, /opt/oracle/product/db10g/bin/*0.
I am not clear as to whether the array has stored the lines from oratab into one line, or it is just the way it lists them. If it lists them all into one line consecutively, then I can see why
my $ORACLE_HOME=$line[1];
only reads the first directory and not one for each line in the oratab. How can I get it to work through the array, line by line? (
Thanks again!
Teresa.
#################################################
/var/opt/oratab contains:
repo:/opt/oracle/product/db10g:Y
agent:/opt/oracle/product/agent10g:Y
oms:/opt/oracle/product/oms10g:Y
emdiag:/opt/oracle/product/emdiag:Y
##################################################
prueba.pl:
#!/usr/bin/perl
use strict;
my @lines=();
my $line;
my @line=();
my $filename = "/var/opt/oratab";
my $bincero;
my @bincero=();
my $perms;
my $dev;
my $pattern;
my @bin;
my @fields=();
# print "Oratab: $filename\n";
#========================================================
#Read from oratab file
#========================================================
open (FILE, "< $filename\n") or die "Cant open $filename: $!\n";
while (<FILE>)
{
s/"*"//; #ignore comments and ORA_HOME with no db defined
next if /^(\s)*$/; #skip blank lines
chomp;
push (@lines, $_);
}
print @lines, "\n";
close FILE;
foreach $line (@lines)
{
@line= split (/:/, $line);
my $instance=$line[0];
my $ORACLE_HOME=$line[1];
my $linea;
my @bincero = `ls -la $ORACLE_HOME/bin/*0`;
my @binO = `ls -la $ORACLE_HOME/bin/*O`;
# my @allredunbins = (@bincero, @binO); #merges both arrays into one.
#print "Redundant binaries ending in O in $ORACLE_HOME, regardless of perms are as follows:\n @allredunbins\n";
foreach $linea(@bincero)
{
@fields = split(m/[\n\t\s]+/, $linea);
$perms = $fields[0];
$dev = $fields[8];
$pattern = "----------";
# {
if ($perms !~ $pattern) #Check for permissions above 000 in each binary.
{print "em_result: Binary $dev has excessive perms: $perms\n"; }
# }
}
exit 0;
}
##########################################################
I need help with a loop in a script that is not doing what I want it to do. I include the whole script at the bottom of this message. The intention is that (1) it reads a file /var/opt/oratab into an array (this works), (2) It should go line by line, and separating the fields by : so that the 2nd one can be assigned to a variable with which I can run an OS command (per line) to check the permissions of bin files within each of these directories.
As it is now, the script prints the @lines array and then it is checking the permissions of the binary files ending in zero in $ORACLE_HOME/bin of the first oratab line, /opt/oracle/product/db10g/bin/*0.
I am not clear as to whether the array has stored the lines from oratab into one line, or it is just the way it lists them. If it lists them all into one line consecutively, then I can see why
my $ORACLE_HOME=$line[1];
only reads the first directory and not one for each line in the oratab. How can I get it to work through the array, line by line? (
Thanks again!
Teresa.
#################################################
/var/opt/oratab contains:
repo:/opt/oracle/product/db10g:Y
agent:/opt/oracle/product/agent10g:Y
oms:/opt/oracle/product/oms10g:Y
emdiag:/opt/oracle/product/emdiag:Y
##################################################
prueba.pl:
#!/usr/bin/perl
use strict;
my @lines=();
my $line;
my @line=();
my $filename = "/var/opt/oratab";
my $bincero;
my @bincero=();
my $perms;
my $dev;
my $pattern;
my @bin;
my @fields=();
# print "Oratab: $filename\n";
#========================================================
#Read from oratab file
#========================================================
open (FILE, "< $filename\n") or die "Cant open $filename: $!\n";
while (<FILE>)
{
s/"*"//; #ignore comments and ORA_HOME with no db defined
next if /^(\s)*$/; #skip blank lines
chomp;
push (@lines, $_);
}
print @lines, "\n";
close FILE;
foreach $line (@lines)
{
@line= split (/:/, $line);
my $instance=$line[0];
my $ORACLE_HOME=$line[1];
my $linea;
my @bincero = `ls -la $ORACLE_HOME/bin/*0`;
my @binO = `ls -la $ORACLE_HOME/bin/*O`;
# my @allredunbins = (@bincero, @binO); #merges both arrays into one.
#print "Redundant binaries ending in O in $ORACLE_HOME, regardless of perms are as follows:\n @allredunbins\n";
foreach $linea(@bincero)
{
@fields = split(m/[\n\t\s]+/, $linea);
$perms = $fields[0];
$dev = $fields[8];
$pattern = "----------";
# {
if ($perms !~ $pattern) #Check for permissions above 000 in each binary.
{print "em_result: Binary $dev has excessive perms: $perms\n"; }
# }
}
exit 0;
}
##########################################################