Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Mar 2012
    Location
    France
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Syntax error: conditional arguments in perl

    Hello,

    I'm writing a small perl script to monitor both zimbra and named, it is based off of this script but I'm having an issue with my last conditional statement. The compiler returns: syntax error at Script line 70 (red line), near ") {"

    Code:
    #!/usr/bin/perl
    
    $zimbra_status_command='sudo -u zimbra /opt/zimbra/bin/zmcontrol status';
    my @services = ( 'named' );
    
    $faulty_service=0;
    $faulty_daemon=0;
    
    open (ZMSTATUS, "$zimbra_status_command |");
    while (<ZMSTATUS>){
    	if (/^Host/){
    		my ($tmp, $hostname)=split();
    	} else {
    		($service, $state)=split();    
    	}
    
    	if ( $state eq "Stopped" ){
    		$faulty_service++;
    	} elsif ( $state eq "is" ){
    		$faulty_daemon++;
    	}
    }
    close (ZMSTATUS);
    
    	if ( $faulty_service > 0 && $faulty_daemon > 0){
    		$zimbra=2;
    		$zimbrastatus="Critical";
    
    	} elsif ( $faulty_service > 0 && $faulty_daemon == 0){
    		$zimbra=1;
    		$zimbrastatus="Warning";
    
    	} elsif ( $faulty_service == 0 && $faulty_daemon == 0){
    		$zimbra=0;
    		$zimbrastatus="Running";
    
    	} else {
    		$zimbra=3;
    		$zimbrastatus="Unknown";
    
    	}
    
    
    foreach my $service (@services) {
    
    my $procstatus = `/bin/ps cax | /bin/grep $service`;
    	
    	if (!$procstatus) {
    		$bind=20;
    		$bindstatus="Down";
    
    	} else {
    		$bind=10;
    		$bindstatus="Running";
    
    	}
    }
    
    
    $status = $bind + $zimbra;
    
    	if ($status == 10){
    		print "OK";
    
    	} elsif ($status != 10){
    		print "Bind" .$bindstatus. ", Zimbra" .$zimbrastatus;
    
    	} else {
    		print "Status Unavailable";
    
    	}
    
    exit;
    Does anyone have any ideas? I've tried googling around but I can't seem to find any answers...

    Thanks a lot!

    Arthur
    Last edited by rthur; 03-28-2012 at 05:23 PM. Reason: Marked as resolved and updated included script to working version.

  • #2
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    You're missing the semi-colon on the line prior to the one you've marked in red and you're missing the semi-colon on a couple other lines.

  • Users who have thanked FishMonger for this post:

    rthur (03-28-2012)

  • #3
    New to the CF scene
    Join Date
    Mar 2012
    Location
    France
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thanks a million! I was pulling my hair out on this one, stupid me...
    For the other missing ones do you mean the ones in the last arguments of my conditional statements? I was under the impression that since those were surrounded in brackets semi colons weren't required on the last statement.

    Thanks a lot!

    Arthur

  • #4
    Super Moderator
    Join Date
    May 2005
    Location
    Southern tip of Silicon Valley
    Posts
    2,877
    Thanks
    2
    Thanked 164 Times in 159 Posts
    It is true that the last statement in a block does not require the semi-colon, but it's best practice to always terminate all statements.

  • #5
    New to the CF scene
    Join Date
    Mar 2012
    Location
    France
    Posts
    8
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Ok, thanks for the pointer, I'll keep it in mind!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •