Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Dec 5th, 2004, 8:49 PM   #1
cyberfunk
Newbie
 
Join Date: Dec 2004
Posts: 2
Rep Power: 0 cyberfunk is on a distinguished road
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)
cyberfunk is offline   Reply With Quote
Old Dec 6th, 2004, 5:25 PM   #2
sykkn
Hobbyist Programmer
 
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5 sykkn is on a distinguished road
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! */
sykkn is offline   Reply With Quote
Old Dec 6th, 2004, 5:50 PM   #3
cyberfunk
Newbie
 
Join Date: Dec 2004
Posts: 2
Rep Power: 0 cyberfunk is on a distinguished road
No, thanks very much!

Your suggestion resolved my problem!!

Cheers

Cyber
cyberfunk is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 12:39 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC