![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Newbie
Join Date: Dec 2004
Posts: 2
Rep Power: 0
![]() |
Hello,
I am trying to run a simple subroutine as part of a script, and I get the following error when I run the program. Global symbol "$arch_log_dir" requires explicit package name at ./chk_archive_lock.pl line 126. Execution of ./chk_archive_lock.pl aborted due to compilation errors. The code to the subroutine is below, and I would appreciate it if someone could show me where I am going wrong, as I am quite new to perl. I have tried putting a "my" infront of the variable name, but it doesn't seem to work... Thanks in advance, Cyber ------------------------------------------------ sub chk_arch_logs_create_time () {
if ( ! -f $lock ) {
# Set archive log directory
if ($hostname eq "hosta001" || $hostname eq "hosta002") {my $arch_log_dir = "/hosta01/oradata/HOSTA/arch";}
elsif ($hostname eq "hostb001" || $hostname eq "hostbb002") {my $arch_log_dir = "/hostb01/oradata/HOSTB/arch";}
else { printf "script not running on a valid host...\n"; exit 0; }
# Check age of archive log files, if > 6 hours old, generate a major USM alarm.
#while (defined(my $filename = <$arch_log_dir/*>)) {
while (my $filename = <$arch_log_dir/*>) {
my $time = time;
my $attrib = (stat($filename))[9];
my $arch_age = ($time-$attrib)/3600;
if ( $arch_age > 6 ) {
printf USM_LOG "$current_day;$hostname;3773;major;Oracle;$oracle_sid;$oracle_sid Backup not running, & archive logs are $arch_age hours old!\n";
} else {
printf USM_LOG "$current_day;$hostname;3773;normal;Oracle;$oracle_sid;$oracle_sid Backups appear to be running. A lock file doesn't exist, and archive logs are only $arch_age hours old.\n";
}
}
}
}(You've been code tagged! ~ SykkN) |
|
|
|
|
|
#2 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
your $arch_log_dir is being scoped inside your if{} blocks. If you want the variable to live through the entire subroutine you need to initiate it inside the sub{} block, but outside any other blocks{}.
sub chk_arch_logs_create_time () {
my $arch_log_dir = '';
if ( ! -f $lock ) {
# Set archive log directory
if ($hostname eq "hosta001" || $hostname eq "hosta002") { $arch_log_dir = "/hosta01/oradata/HOSTA/arch";}
elsif ($hostname eq "hostb001" || $hostname eq "hostbb002") { $arch_log_dir = "/hostb01/oradata/HOSTB/arch";}
else { printf "script not running on a valid host...\n"; exit 0; }
# Check age of archive log files, if > 6 hours old, generate a major USM alarm.
#while (defined(my $filename = <$arch_log_dir/*>)) {
while (my $filename = <$arch_log_dir/*>) {
my $time = time;
my $attrib = (stat($filename))[9];
my $arch_age = ($time-$attrib)/3600;
if ( $arch_age > 6 ) {
printf USM_LOG "$current_day;$hostname;3773;major;Oracle;$oracle_sid;$oracle_sid Backup not running, & archive logs are $arch_age hours old!\n";
} else {
printf USM_LOG "$current_day;$hostname;3773;normal;Oracle;$oracle_sid;$oracle_sid Backups appear to be running. A lock file doesn't exist, and archive logs are only $arch_age hours old.\n";
}
}
}
}was kind of a quick/dirty explantion. Please let me know if you need any clarification.
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ]; /* Don't make me use it! */ |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Dec 2004
Posts: 2
Rep Power: 0
![]() |
No, thanks very much!
Your suggestion resolved my problem!! Cheers ![]() Cyber |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|