3

Here is the scenario,

$hostname
server1

I have the below script in server1,

#!/bin/ksh
echo "Enter server name:"
read server

rsh -n ${server} -l mquser "/opt/hd/ca/scripts/envscripts.ksh"
qdisplay
 # script ends.

In above script I am logging into another server say server2 and executing the script "envscripts.ksh" which sets few alias(Alias "qdisplay") defined in it.

I can able to successfully login to server1 but unable to use the alias set by script "envscripts.ksh".

Geting below error,

-bash: qdisplay: command not found

can some please point out what needs to be corrected here.

Thanks, Vignesh

T.Rob
  • 31,522
  • 9
  • 59
  • 103
Vignesh
  • 949
  • 2
  • 21
  • 38
  • 1. do you mean rsh (not rosh)? 2. do you use bash as your local cmd line shell when you run this script AND/OR 3. is the mquser on ${server} using bash as its login shell? – shellter Mar 08 '11 at 19:59

2 Answers2

1

The other responses and comments are correct. Your rsh command needs to execute both the ksh script and the subsequent command in the same invocation. However, I thought I'd offer an additional suggestion.

It appears that you are writing custom instrumentation for WebSphere MQ. Your approach is to remote shell to the WMQ server and execute a command to display queue attributes (probably depth).

The objective of writing your own instrumentation is admirable, however attempting to do it as remote shell is not an optimal approach. It requires you to maintain a library of scripts on each MQ server and in some cases to maintain these scripts in different languages.

I would suggest that a MUCH better approach is to use the MQSC client available in SupportPac MO72. This allows you to write the scripts once, and then execute them from a central server. Since the MQSC commands are all done via MQ client, the same script handles Windows, UNIX, Linux, iSeries, etc.

For example, you could write a script that remotely queried queue depths and printed a list of all queues with depth > 0. You could then either execute this script directly against a given queue manager or write a script to iterate through a list of queue managers and collect the same report for the entire network. Since the scripts are all running on the one central server, you do not have to worry about getting $PATH right, differences in commands like tr or grep, where ksh or perl are installed, etc., etc.

Ten years ago I wrote the scripts you are working on when my WMQ network was small. When the network got bigger, these platform differences ate me alive and I was unable to keep the automation up and running. When I switched to using WMQ client and had only one set of scripts I was able to keep it maintained with far less time and effort.

The following script assumes that the QMgr name is the same as the host name except in UPPER CASE. You could instead pass QMgr name, hostname, port and channel on the command line to make the script useful where QMgr names do not match the host name.

#!/usr/bin/perl -w
#-------------------------------------------------------------------------------
# mqsc.pl
#
# Wrapper for M072 SupportPac mqsc executable
# Supply parm file name on command line and host names via STDIN.
# Program attempts to connect to hostname on SYSTEM.AUTO.SVRCONN and port 1414 
# redirecting parm file into mqsc.
#
# Intended usage is...
#
# mqsc.pl parmfile.mqsc
# host1
# host2
# 
# -- or --
#
# mqsc.pl parmfile.mqsc < nodelist
#
# -- or --
#
# cat nodelist | mqsc.pl parmfile.mqsc
#
#-------------------------------------------------------------------------------
use strict;
$SIG{ALRM} = sub { die "timeout" };

$ENV{PATH} =~ s/:$//;

my $File = shift;
die "No mqsc parm file name supplied!" unless $File;
die "File '$File' does not exist!\n"   unless -e $File;

while () {
    my @Results;
    chomp;
    next if /^\s*[#*]/; # Allow comments using # or *
    s/^\s+//;  # Delete leading whitespace
    s/\s+$//;  # Delete trailing whitespace
    # Do not accept hosts with embedded spaces in the name
    die "ERROR: Invalid host name '$_'\n" if /\s/;

    # Silently skip blank lines
    next unless ($_);

    my $QMgrName = uc($_);

    #----------------------------------------------------------------------------
    # Run the parm file in
    eval {
        alarm(10);
        @Results = `mqsc -E -l -h $_ -p detmsg=1,prompt="",width=512 -c SYSTEM.AUTO.SVRCONN &1 | grep -v "^MQSC Ended"`;
    };

    if ($@) {
        if ($@ =~ /timeout/) {
            print "Timed out connecting to $_\n";
        } else {
            print "Unexpected error connecting to $_: $!\n";
        }
    }
    alarm(0);

    if (@Results) {
        print join("\t", @Results, "\n");
    }
}
exit;

The parmfile.mqsc is any valid MQSC script. One that gathers all the queue depths looks like this:

DISPLAY QL(*) CURDEPTH
T.Rob
  • 31,522
  • 9
  • 59
  • 103
0

I think the real problem is that the r(o)sh cmd only executes the remote envscripts.ksh file and that your script is then trying to execute qdisplay on your local machine.

You need to 'glue' the two commands together so they are both executed remotely. EDITED per comment from Gilles (He is correct)

rosh -n ${server} -l mquser ". /opt/hd/ca/scripts/envscripts.ksh ; qdisplay"

I hope this helps.

P.S. as you appear to be a new user, if you get an answer that helps you please remember to mark it as accepted, or give it a + (or -) as a useful answer

shellter
  • 36,525
  • 7
  • 83
  • 90
  • That's not enough. You need to arrange for the alias definitions and the use of the alias to be executed in the same shell. Since the definitions are in a separate script, you need to source the definition script (`.` command) rather than execute it as a separate process: `rosh -n ${server} -l mquser ". /opt/hd/ca/scripts/envscripts.ksh ; qdisplay"`. – Gilles 'SO- stop being evil' Mar 08 '11 at 22:13
  • Correct, I have modified my answer per your comment. Thanks – shellter Mar 09 '11 at 01:01
  • Hello Shellter, I tried the above idea. But it is not working. Only envscripts.ksh is executing but "qdisplay" which is an alias for another script is not getting executed . Note: envscripts.ksh sets alias(qdisplay) for their necessary scripts. Thanks,Vignesh – Vignesh Mar 09 '11 at 17:28
  • Please answer the questions 1-4 in my comments to your original post. *Also, did using the answer above eliminate the output "-bash: qdisplay: command not found" ? – shellter Mar 09 '11 at 19:26