Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   Perl (http://www.programmingforums.org/forum21.html)
-   -   Global Symbol Error (http://www.programmingforums.org/showthread.php?t=1436)

cyberfunk Dec 5th, 2004 9:49 PM

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)

sykkn Dec 6th, 2004 6:25 PM

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.

cyberfunk Dec 6th, 2004 6:50 PM

No, thanks very much!

Your suggestion resolved my problem!!

Cheers :)

Cyber


All times are GMT -5. The time now is 3:32 AM.

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