Syntax error near unexpected token `$MQ_LOG'


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Syntax error near unexpected token `$MQ_LOG'
# 1  
Old 07-03-2013
Syntax error near unexpected token `$MQ_LOG'

Code:
#/usr/bin/perl
#################################################################################################
#												#
# mqftp 	: This program can start/stop all the qmgr that are running on the give host
#			or can select particular qmgr to start/stop
####################################################

select STDOUT; #$| = 1; 
$MQ_LOG = 'console.log';
sub usage {
    print "Usage, $0 qmgrname|all stop|start\n";
    print "OR    $0 status \n";
    exit 1;
}

sub trim($)
{
	my $string = shift;
	$string =~ s/^\s+//;
	$string =~ s/\s+$//;
	return $string;
}


sub stopqmgr{
	my $qmgr = shift;
	#print("stoping  qmgr: $qmgr called \n");
	@status = `endmqm -i $qmgr`;
#	print("printing status \n");	
	#print @status;
}

sub startqmgr{
	my $qmgr = shift;
	#print("start qmgr $qmgr called\n");
	@status = `strmqm  $qmgr`;
	print @status;	
}


sub validate_user{
	$ami = `whoami`;
	$groups = `groups $ami`;
	if ($groups =~ m/mqm/){
	#	print " Has access....$groups  \n";
	}else{
		print " You are not alowed to perform any of these operation ....\n $groups \n ";
		exit(1);
	}
}

sub do_ctl
{
	if ($#_ < 1) {
        usage();
	}
	
	validate_user(); 

	my $qmgr_list = get_qmgrs();

       # print all the qmgr and their status 

	 #foreach  $qmgr ( keys(%$qmgr_list)){
         #      	print("$qmgr \t : \t $qmgr_list->{$qmgr}\n");
         #}

        if($ARGV[0] eq 'all' && $ARGV[2] eq '')
        {
		if($ARGV[1] eq 'stop')
                {
			foreach  $qmgr ( keys(%$qmgr_list)){
                       		#print("$qmgr \t : \t $qmgr_list->{$qmgr}\n");
				
				if($qmgr_list->{$qmgr} eq 'Running')
				{
					stopqmgr($qmgr);
				}
       			}
                }
                elsif($ARGV[1] eq 'start')
                {
			foreach  $qmgr ( keys(%$qmgr_list)){
                                #print("$qmgr \t : \t $qmgr_list->{$qmgr}\n");
                                if($qmgr_list->{$qmgr} eq 'NotRunning')
                                {
                                        startqmgr($qmgr);
                                }
                        }

                }
		else{
			print " Invalid Argument: $ARGV[1] \n ";
			usage();
		}
		
        }
	else{
		$qmgr_found = 1;
		$search_str = $ARGV[2];
		#print" selected qmgr $ARGV[0] ... $qmgr_list->{$ARGV[0]}  \n";
		
		if ($ARGV[2] eq '')
		{
			$search_str = $ARGV[0];
		}
		foreach  $qmgr ( keys(%$qmgr_list)){
			$qmgr_found = 1;
 			#print("$qmgr \t : \t $qmgr_list->{$qmgr}\n");
			if( $qmgr =~ m/$search_str/)
			{
				
				#print("match $qmgr $qmgr_found  \n");
				if ($qmgr_list->{$qmgr} eq 'Running')
              			  {
                        		if($ARGV[1] eq 'stop')
                        		{
                                		#print("stop qmgr called");
                                 		stopqmgr($qmgr);
                        		}else{
                                		print " $qmgr is already running \n";
                        		}
                		}
                		else
	                	{
        	               		# print "qmgr status is :  $qmgr_list->{$qmgr}   \n";
	        	                if($ARGV[1] eq 'start')
        	        	        {
                	        	        #print("start qmgr called");
                        	        	 startqmgr($qmgr);
		                        }else{
        		                        print " $qmgr is not  running \n";
                		        }
                		}

			}
			else
			{
				$qmgr_found =0;	
				#print("no matching found $qmgr  $qmgr_found \n");
			}
  		}
     }
}


sub get_qmgrs
{
	my %htab;
	my @qmgrs = map { (split)[0..1] } grep { /QMNAME/  } `dspmq`;
	foreach $i (@qmgrs)
	{
		#print " in get_qmgrs : $i \n";
		my @tmp;
		$i =~ m/^QMNAME\((\w+)\)/;
		$tmp[0] = $1;
		$i =~ m/^STATUS\((\w+)\)/;
		$tmp[1] = $1;
		if ($tmp[1] =~  m/Running/)
		{
			$htab{$tmp[0]} = $tmp[1];
		}
		else
		{
			$htab{$tmp[0]} = 'NotRunning';
		}
		
	}
	foreach   $key (keys(%htab))
	 {
		 #print "$key \t : $htab{$key} \n";
	 }
	return \%htab;
}

sub do_status
{
	open(F,"dspmq |");
	while(defined(my $line = <F>)) {
		my @tmp = split /\(+/,$line;
		@tmp1 = split /\)/,$tmp[1];
	       
                @tmp2 = split /\)/,$tmp[2];
		$qmgr = $tmp1[0];
		$status = $tmp2[0];

		if ($status eq 'Running')
	        {
			my @lsr = map { (split)[7..15] } grep { /runmqlsr/ && /$qmgr/  } `/bin/ps -ef`;
			$i=0;	
			foreach $line (@lsr)
			{	
				if ($line eq '-p') 
				{
					$port= $lsr[$i+1];
				}
				$i=$i+1;
			}
	        }
		else
		{
			$port = '';
		}
		print ("$qmgr \t $status \t $port \n");
		push @qmgr_status, "$qmgr \t $status \t $port";
		$port = '';
    	}  
}

    #if ($ARGV[0] eq "status") {
	select STDOUT; $| = 1;

        $curdir = trim(`pwd`);
        my @tmp = split /\//,$curdir;

	$MQ_LOG = "/$tmp[1]/mqtrace/adminlog/console.log"; 
	#print "$MQ_LOG \n";
	open (MQLOG, '>>'.$MQ_LOG);
	$user = trim(`whoami`);
	print(MQLOG  localtime(time)." ($user)  command : $ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] \n");

	close MQLOG;

if ($ARGV[0] eq "status") {
	do_status(@ARGV);
     }
    else {
        do_ctl(@ARGV);
     }

---------- Post updated at 03:51 AM ---------- Previous update was at 03:46 AM ----------

i am new to perl scripts. i want to start the queue manager but getting the above message. very urgent to me, any ideas to resolve the error

---------- Post updated at 03:54 AM ---------- Previous update was at 03:51 AM ----------

run the script as
./filename.pl MB7QMGR
MB7QMGR is queue manager name
# 2  
Old 07-03-2013
why there is # here?
Code:
select STDOUT; #$| = 1; 
$MQ_LOG = 'console.log';

also I can see $MQ_LOG = "/$tmp[1]/mqtrace/adminlog/console.log";

What are you trying to do here?
# 3  
Old 07-03-2013
thank you MR. vidyadhar85

i run the script successfully
mistake is shebang line and this is commented #$| = 1;
$MQ_LOG = "/$tmp[1]/mqtrace/adminlog/console.log"; this for to get the o/p what action done while running the script, we have to create the directories to save the console.log file

---------- Post updated at 04:44 AM ---------- Previous update was at 04:43 AM ----------

i am trying to start/stop/status the list of queue managers
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Ubuntu

Syntax error near unexpected token `('

detect_mouse_mvt.sh /home/andy/bin/detect_mouse_mvt.sh: line 4: syntax error near unexpected token `(' /home/andy/bin/detect_mouse_mvt.sh: line 4: `fh = file('/dev/input/mice')' #!/bin/bash # # fh = file('/dev/input/mice') while True: fh.read(3) print 'Mouse... (15 Replies)
Discussion started by: drew77
15 Replies

2. UNIX for Beginners Questions & Answers

Syntax error near unexpected token

Dears, While executing the below script im getting the error at line 30. Please let me know what changes to be done to fix this. test.sh: line 30: syntax error near unexpected token `done' test.sh: line 30: ` done ' #!/bin/sh # Rev. PA1 # author: eillops # date: 26-04-2018 # #... (1 Reply)
Discussion started by: Kamesh G
1 Replies

3. How to Post in the The UNIX and Linux Forums

Syntax error near unexpected token `('

I have 2 files like a.txt and b.txt and the content is as below cat a.txt 810750125 117780 /BSCSQAT4A/bscsqat4a/lib/jar/wclt_common.jar 1803152428 13300 /BSCSQAT4A/bscsqat4a/lib/jar/WFMSSupportTool.jar 2663502779 67049 /BSCSQAT4A/bscsqat4a/lib/jar/wma.jar 687942896 665272... (1 Reply)
Discussion started by: ranabhavish
1 Replies

4. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hello every one!! I don't know where I am going wrong but I am finding it difficult to clear this error of syntax error near unexpected token `else' I am writing a simple shell script to find a file in a directory and if found execute that else return an error to the log file ... (14 Replies)
Discussion started by: masubram
14 Replies

5. Shell Programming and Scripting

Syntax error near unexpected token

Hi all, I have a simple script that doesn't work somehow. I can't seem to be spotting the cause of the malfunction. count=$((1)) for item in `cat test1.txt` printf %s `sed -n $((count))p test2.txt` > test3.txt count=$((count+1)) do something done I get ; ./why.sh: line 3:... (14 Replies)
Discussion started by: y33t
14 Replies

6. Shell Programming and Scripting

Syntax error near unexpected token '('

I tried to execute the code but I got this error ./Array.c: line 9: syntax error near unexpected token '(' ./Array.c: line 9: ' nvals = get_data(a,MAXARRAY);' and #include<stdio.h> #define MAXARRAY 1000 main() { int a, nvals; nvals =... (7 Replies)
Discussion started by: sgradywhite
7 Replies

7. Shell Programming and Scripting

Syntax error near unexpected token `else'

Hi, I am trying to read the session log through script. But it keeps showing me some error near. I have tried everything. Even tried converting the script using sed command to remove the hidden characters(\r).But nothing seems to be working.Below is the script : #!/bin/bash cd... (6 Replies)
Discussion started by: Aryan12345
6 Replies

8. Shell Programming and Scripting

Syntax error near unexpected token `('

What do I do here? #!/bin/bash payload=-1 AND 1=IF(21,BENCHMARK(5000000,MD5(CHAR(115,113,108,109,97,112))),0)# hash=`echo -n $payload md5sum tr -d 'n' sed 'ss-sg' md5sum tr -d 'n' sed 'ss-sg'` curl --data cs2=chronopay&cs1=$payload&cs3=$hash&transaction_type=rebill... (2 Replies)
Discussion started by: iiiiiiiiiii
2 Replies

9. Shell Programming and Scripting

Syntax error near unexpected token `}' please help

I'm going mad not being able to get this to work. im assuming its only a simple mistake but its driving me bonkers trying to find it. Please if you can help me it would save me pulling my hair out!! Thanks #!/bin/bash -xv # #Config name="TEST Server" + name='TEST Server'... (6 Replies)
Discussion started by: Fisheh
6 Replies

10. Shell Programming and Scripting

syntax error near unexpected token `='

Hi all, This is a script which converts hex to bin. However am finding an error while executing syntax error near unexpected token `=' `($hexfile, $binfile) = @ARGV;' I am running using ./fil.pl <hexfile> <binfile> ################################################### # # this script... (3 Replies)
Discussion started by: jaango123
3 Replies
Login or Register to Ask a Question