#/usr/bin/perl select STDOUT; $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 ope +ration ....\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->{$qm +gr}\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->{$qm +gr}\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 call +ed"); stopqmgr($qmgr); }else{ print " $qmgr is alrea +dy running \n"; } } else { # print "qmgr status is : $qm +gr_list->{$qmgr} \n"; if($ARGV[1] eq 'start') { #print("start qmgr cal +led"); 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 { /runmq +lsr/ && /$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 = "/WebSphere/mqtrace/adminlog/console.log"; #print "$MQ_LOG \n"; open (MQLOG, '>>'.$MQ_LOG); $user = trim(`whoami`); print(MQLOG localtime(time)." ($user) command : $ARGV[0] $AR +GV[1] $ARGV[2] $ARGV[3] \n"); close MQLOG; if ($ARGV[0] eq "status") { do_status(@ARGV); } else { do_ctl(@ARGV); }
when i run the script like
./qmgrRestart.pl MB7QMGR with file name and qmgr name getting the e +roor ./qmgrRestart.pl: line 14: syntax error near unexpected token `$MQ_LOG +' ./qmgrRestart.pl: line 14: `$MQ_LOG = 'console.log';'

In reply to perl script to start the queu manger by DonCnu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.