Tool to get MCP ODT at Windows CMD prompt
- From: MCP_Fanatic@xxxxxxxxxxxxxxx
- Date: Sun, 28 May 2006 02:56:09 GMT
I thought I would share a nifty little tool I wrote for our ClearPath MCP system. It's a way of getting ODT data at a Windows CMD
prompt. You basically send a series of ODT commands of your choosing, once, or in a loop, and get the output right in the command
window. You can also redirect to a file if you wish. You can even put that file back up on the MCP if you desire by giving the name
of the file an URL which points back to the MCP system. I use the script to monitor what's going on in the system and keep a record
of MCP utilization throughout the day. I find it much easier than loganalyzer or other utilities as all I need to search through my
records is a text editor. Heck even the findstr command works well enough for most things!
I call this ConODT (short for Console ODT). You can choose between the VB Script or Perl implementations. If you use the VB Script
version, be sure to run it with Cscript, not Wscript. Since script attachments are frowned on in newsgroups, I'll just put the code
in this message and you can cut and paste it into your own file. It leverages the MCPINFO component which you find in the INSTALLS
directory share on your MCP system. Be sure you install MCPINFO before you run the script or the script will fail due to it's
inability to instantiate the COM object. Obviously you need to have the required privileges on the MCP side as well with the
credentials you connect with.
Here is the syntax:
Usage: ConODT.vbs hostname [-u usercode] [-p password] [-c command list]
[-d delay between commands] [-i interval between cycles]
[-n number of cycles] [-f output file] [-o]
hostname = Required. The name of the ClearPath host to connect to
-u usercode = Optional. Usercode for ClearPath host. You must supply
this argument if you are using the credentials
of someone other than the currently connected
user
-p password = Optional. Password for usercode on ClearPath host. You
supply this argument if you are using the
credentials of someone other than the currently
connected user
-c command list = Optional. Comma seperated list of commands to send to
ClearPath Host. Enclose in quotes if it includes
blanks. Default is a,w,s,c,msg
Example: -c "u,cu,a sort cpurate"
-d delay = Optional. How much time, in seconds, to delay between
each command in the command list. Default
is 5 seconds
-i interval = Optional. How much time, in seconds, to delay
between the last command of a cycle and the
first command of the next cycle. Default Is
0 seconds
-n number of cycles = Optional. How many cycles to run prior to
termination. Default is to run forever.
-f output file = Optional. The file name of where to write a text file
containing a copy of the output which is sent to
StdOut. It will be created if it does not exist
and appended to if it does exist.
-o = Optional. Do one cycle only then exit. Good for a quick look
Examples:
ConODT.vbs MyLX7100 -u Admin -p Admin -c msg -o
Connects to MyLX7100 using credentials Admin/Admin and does one cycle
of the msg command sending the output to StdOut only
ConODT.vbs DataCenter -c "u,dbs,per pk" -d 10 -f OdtOut.txt
Connects to the machine named DataCenter using the current users
credentials and cycles through the u, dbs, and per pk commands
delaying 10 seconds between commands. The output will be written
to a file titled OdtOut.txt
ConODT.vbs lxlaptop -c a,u,cu -d 0 -i 30
Connects to lxlaptop using the current users credentials and
issue the a, u, and cu commands with no delay between them but
waits 30 seconds after issuing the CU command before it issues
the next cycle of commands
Here is the VBScript code:
'==========================================================================
'
' VBScript Source File -- Created with SAPIEN Technologies PrimalScript 3.1
'
' NAME: ConODT.vbs
'
' DATE : 6/6/2005
'
' COMMENT: Console version of an ODT
'
'==========================================================================
Option Explicit
Const FORREADING = 1
Const FORWRITING = 2
Const FORAPPENDING = 8
Dim sHostname
Dim sUsercode
Dim sPassword
Dim sFileName
Dim sQuote
Dim StdIn, StdOut
Dim sODTCommands
Dim iDelaySec, iIntervalSec, bOneCycle, iNumCycles
Dim WSHNetwork, MCPSession, MCPDCKeyin
Dim oFSO,fOut
Sub WriteIt(ByVal sLine)
StdOut.WriteLine sLine
If Not (fOut is Nothing) Then
fOut.WriteLine sLine
End If
End Sub
Sub Help
WriteIt "Usage: " & WScript.ScriptName & " hostname [-u usercode] [-p password] [-c command list]"
WriteIt String(Len("Usage: ")," ") & "[-d delay between commands] [-i interval between cycles]"
WriteIt String(Len("Usage: ")," ") & "[-n number of cycles] [-f output file] [-o]"
WriteIt ""
WriteIt " hostname = Required. The name of the ClearPath host to connect to"
WriteIt " -u usercode = Optional. Usercode for ClearPath host. You must supply"
WriteIt " this argument if you are using the credentials "
WriteIt " of someone other than the currently connected "
WriteIt " user"
WriteIt " -p password = Optional. Password for usercode on ClearPath host. You"
WriteIt " supply this argument if you are using the "
WriteIt " credentials of someone other than the currently"
WriteIt " connected user"
WriteIt " -c command list = Optional. Comma seperated list of commands to send to"
WriteIt " ClearPath Host. Enclose in quotes if it includes"
WriteIt " blanks. Default is a,w,s,c,msg"
WriteIt " Example: -c " & sQuote & "u,cu,a sort cpurate" & sQuote
WriteIt " -d delay = Optional. How much time, in seconds, to delay between"
WriteIt " each command in the command list. Default"
WriteIt " is 5 seconds"
WriteIt " -i interval = Optional. How much time, in seconds, to delay "
WriteIt " between the last command of a cycle and the"
WriteIt " first command of the next cycle. Default Is"
WriteIt " 0 seconds"
WriteIt " -n number of cycles = Optional. How many cycles to run prior to"
WriteIt " termination. Default is to run forever."
WriteIt " -f output file = Optional. The file name of where to write a text file "
WriteIt " containing a copy of the output which is sent to"
WriteIt " StdOut. It will be created if it does not exist"
WriteIt " and appended to if it does exist."
WriteIt " -o = Optional. Do one cycle only then exit. Good for a quick look"
WriteIt ""
WriteIt ""
WriteIt " Examples:"
WriteIt ""
WriteIt " " & WScript.ScriptName & " MyLX7100 -u Admin -p Admin -c msg -o"
WriteIt " Connects to MyLX7100 using credentials Admin/Admin and does one cycle"
WriteIt " of the msg command sending the output to StdOut only"
WriteIt ""
WriteIt " " & WScript.ScriptName & " DataCenter -c " & sQuote & "u,dbs,per pk" & sQuote & " -d 10 -f OdtOut.txt"
WriteIt " Connects to the machine named DataCenter using the current users"
WriteIt " credentials and cycles through the u, dbs, and per pk commands"
WriteIt " delaying 10 seconds between commands. The output will be written"
WriteIt " to a file titled OdtOut.txt"
WriteIt ""
WriteIt " " & WScript.ScriptName & " lxlaptop -c a,u,cu -d 0 -i 30"
WriteIt " Connects to lxlaptop using the current users credentials and"
WriteIt " issue the a, u, and cu commands with no delay between them but"
WriteIt " waits 30 seconds after issuing the CU command before it issues"
WriteIt " the next cycle of commands"
End Sub
Sub FatalError (ByVal sMsg)
WriteIt sMsg
WScript.Quit 2
End Sub
Sub Initialize
Dim objArgs
Dim I
sQuote = Chr(34)
Set StdIn = WScript.StdIn
Set StdOut = WScript.StdOut
Set objArgs = WScript.Arguments
Set WSHNetwork = CreateObject("WScript.Network")
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fOut = Nothing
If objArgs.Count = 0 Then
Help
WScript.Quit 1
End If
If (objArgs.Count = 1) And _
((objArgs(0) = "-h") Or _
(objArgs(0) = "/?") Or (objArgs(0) = "/h") OR _
(Left(objArgs(0),1)) = "-") Then
Help
WScript.Quit 1
Else
iDelaySec = 5 ' Default to 5 seconds between commands
iIntervalSec = 0
iNumCycles = -1 ' Default is to run forever
sODTCommands = Array("a","w","s","c","msg")
sHostname = objArgs(0)
sUsercode = ""
sPassword = ""
sFileName = ""
bOneCycle = False
If (objArgs.Count = 1) Then
Exit Sub ' Using all default
End If
I = 1
Do
Select Case LCase(objArgs(I))
Case "-u"
I = I + 1
sUsercode = CStr(objArgs(I))
I = I + 1
Case "-p"
I = I + 1
sPassword = objArgs(I)
I = I + 1
Case "-c"
I = I + 1
sODTCommands = Split(objArgs(I),",")
I = I + 1
Case "-f"
I = I + 1
sFileName = objArgs(I)
If oFSO.FileExists(sFileName) Then
Set fOut = oFSO.OpenTextFile(sFileName,FORAPPENDING,False)
Else
Set fOut = oFSO.OpenTextFile(sFileName,FORWRITING, True)
End If
I = I + 1
Case "-d"
I = I + 1
iDelaySec = CInt(objArgs(I))
I = I + 1
Case "-i"
I = I + 1
iIntervalSec = CInt(objArgs(I))
I = I + 1
Case "-o"
I = I + 1
bOneCycle = True
iNumCycles=1
Case "-n"
I = I + 1
iNumCycles = CInt(objArgs(I))
I = I + 1
Case Else
WScript.Echo "Unrecognized switch = " & objArgs(I)
I = I + 1
End Select
Loop Until I >= objArgs.Count
End If
End Sub
Sub ConnectToHost
Dim sHost
On Error Resume Next
Set MCPSession = CreateObject("Unisys.MCPInfo")
If Err Then
FatalError "Unable to create Unisys.MCPInfo. Error = " & Err.Description & VbCrLf
End If
If sUsercode <> "" Then
sHost = "\\" & sHostname & "\IPC$"
WSHNetwork.MapNetworkDrive "",sHost , False, sUsercode, sPassword
If Err Then
FatalError "Unable to map to " & sHost & ". Error = " & Err.Description & VbCrLf
End If
End If
MCPSession.Connect sHostname
If Err Then
FatalError "Unable to connect to an MCPSession on " & sHostname & ". Error = " & Err.Description & VbCrLf
End If
Set MCPDCKeyin = MCPSession.DCKeyinInterface
If Err Then
FatalError "Unable to create a DCKeyinInterface. Error = " & Err.Description & VbCrLf
End If
End Sub
Sub ODTCommand(ByVal sCmd)
Dim sResponse
Dim MCPLine
Dim tNow
MCPDCKeyin.Initiate sCmd
If Err Then
NonFatalError "Unable to send the command " & sCmd & "to sHostname. Error = " & Err.Description & VbCrLf
End If
tNow = Now
WriteIt FormatDateTime(tNow,vbLongDate) & " @ " & FormatDateTime(tNow,vbLongTime) & ":" & sCmd
sResponse = ""
For Each MCPLine in MCPDCKeyin.ResponseLines
sResponse = sResponse & MCPLine & VbCrLf
Next
WriteIt sResponse
End Sub
Sub CycleODTCommands
Dim sOdtCmd
Dim I
I = 0
While (iNumCycles <> 0)
Do ' Each command in sODTCommands
ODTCommand sODTCommands(I)
If Not( (iNumCycles=1) And (I = UBound(sODTCommands)) ) Then ' Don't sleep on very last command
WScript.Sleep iDelaySec*1000
End If
I = I + 1
Loop Until I > UBound(sODTCommands)
If bOneCycle Then
WScript.Quit 0
End If
If iNumCycles > 0 Then
iNumCycles = iNumCycles - 1
End If
I = 0
WScript.Sleep iIntervalSec*1000
Wend
End Sub
Initialize
ConnectToHost
CycleODTCommands
And here is the perl version
# ======================================================================
#
# Perl Source File -- Created with SAPIEN Technologies PrimalScript 3.1
#
# NAME: ConODT.pl
#
# DATE : 6/8/2005
#
# PURPOSE: Console version of an ODT
#
# ======================================================================
use strict; # because I make too many mistakes!
use OLE;
use WIN32;
use Time::Local;
use IO::Handle;
my $hostname; # name of ClearPath host
my $usercode; # usercode for ClearPath
my $password; # password for ClearPath
my $filename; # Output file name
my $odtcommands;# a string including commas
my $delaysec; # seconds to wait between commands
my $intervalsec;# seconds to wait between cycles
my $numcycles; # how many cycles to perform
my $onceonly; # true if we do one cycle only
my $MCPSession;
my $WSHNetwork;
my $MCPDCKeyin;
Initialize();
ConnectToHost();
CycleODTCommands();
sub WriteIt
{
foreach $_ (@_)
{
print $_;
if ($filename)
{
print F $_;
}
}
}
sub Help
{
WriteIt "Usage: $0 hostname [-u usercode] [-p password] [-c command list]\n";
WriteIt " [-d delay between commands] [-i interval between cycles]\n";
WriteIt " [-n number of cycles] [-f output file] [-o]\n";
WriteIt "\n";
WriteIt " hostname = Required. The name of the ClearPath host to connect to\n";
WriteIt " -u usercode = Optional. Usercode for ClearPath host. You must supply\n";
WriteIt " this argument if you are using the credentials\n";
WriteIt " of someone other than the currently connected\n";
WriteIt " user\n";
WriteIt " -p password = Optional. Password for usercode on ClearPath host. You\n";
WriteIt " supply this argument if you are using the\n";
WriteIt " credentials of someone other than the currently\n";
WriteIt " connected user\n";
WriteIt " -c command list = Optional. Comma seperated list of commands to send to\n";
WriteIt " ClearPath Host. Enclose in quotes if it includes\n";
WriteIt " blanks. Default is a,w,s,c,msg\n";
WriteIt " Example: -c \"u,cu,a sort cpurate\"\n";
WriteIt " -d delay = Optional. How much time, in seconds, to delay between\n";
WriteIt " each command in the command list. Default\n";
WriteIt " is 5 seconds\n";
WriteIt " -i interval = Optional. How much time, in seconds, to delay\n";
WriteIt " between the last command of a cycle and the\n";
WriteIt " first command of the next cycle. Default is\n";
WriteIt " 0 seconds\n";
WriteIt " -n number of cycles = Optional. How many cycles to run prior to\n";
WriteIt " termination. Default is to run forever.\n";
WriteIt " -f output file = Optional. The file name of where to write a text file\n";
WriteIt " containing a copy of the output which is sent to\n";
WriteIt " StdOut. It will be created if it does not exist\n";
WriteIt " and appended to if it does exist.\n";
WriteIt " -o = Optional. Do one cycle only then exit. Good for a quick look\n";
WriteIt "\n";
WriteIt "\n" ;
WriteIt " Examples:\n";
WriteIt "\n" ;
WriteIt " ConODT.plx MyLX7100 -u Admin -p Admin -c msg -o\n";
WriteIt " Connects to MyLX7100 using credentials Admin/Admin and does one cycle\n";
WriteIt " of the msg command sending the output to StdOut only\n";
WriteIt "\n" ;
WriteIt " ConODT.plx DataCenter -c \"u,dbs,per pk\" -d 10 -f OdtOut.txt\n";
WriteIt " Connects to the machine named DataCenter using the current users\n";
WriteIt " credentials and cycles through the u, dbs, and per pk commands\n";
WriteIt " delaying 10 seconds between commands. The output will be written\n";
WriteIt " to a file titled OdtOut.txt\n";
WriteIt "\n";
WriteIt " ConODT.plx lxlaptop -c a,u,cu -d 0 -i 30\n";
WriteIt " Connects to lxlaptop using the current users credentials and\n";
WriteIt " issue the a, u, and cu commands with no delay between them but\n";
WriteIt " waits 30 seconds after issuing the CU command before it issues\n";
WriteIt " the next cycle of commands\n";
}
sub Initialize
{
my @args;
my $thisarg;
my $thisoption;
$WSHNetwork = CreateObject OLE "Wscript.Network" or die "Unable to create WSHNetwork";
$delaysec = 5;
$intervalsec = 0;
$onceonly = 0;
$numcycles = -1;
$odtcommands = 'a,w,s,c,msg';
if ($#ARGV==-1) # No parameters provided. Show help
{
Help();
exit 1;
}
@args = reverse(@ARGV); # reverse the order so pop
# gets first argument first
# handle the first argument differently
# it must either be a request for help or the hostname
$thisarg = pop(@args);
if ($thisarg=~/^\-/) # does the argument start with a -
{
Help();
exit 1;
}
# if we get here it mut be the hostname
$hostname = $thisarg;
while (@args)
{
$thisarg = pop(@args);
$thisoption = substr($thisarg,1,1);
if ($thisoption eq "u") # usercode
{
$usercode = pop(@args);
}
elsif ($thisoption eq "p") #passowrd
{
$password = pop(@args);
}
elsif ($thisoption eq "c") # command list
{
#WriteIt('$odtcommands was ' . "$odtcommands");
$odtcommands = pop(@args);
#WriteIt(' $odtcommands is now ' . "$odtcommands\n");
}
elsif ($thisoption eq "f") # filename
{
$filename = pop(@args);
# see if the file exists. If so append, if not, create
if (-e $filename)
{
# it does exist
open(F,">>$filename") || die "Unable to open $filename for appending. $!\n";
}
else
{
# it does not exist
open(F,">$filename") || die "Unable to open $filename for writing. $!\n";
}
autoflush F 1;
}
elsif ($thisoption eq "d") # delay
{
$delaysec = pop(@args);
}
elsif ($thisoption eq "i") # interval
{
$intervalsec = pop(@args);
}
elsif ($thisoption eq "o") # onecycle
{
$onceonly++;
$numcycles = 1;
}
elsif ($thisoption eq "n") # number of cycles
{
$numcycles = pop(@args);
}
else
{
WriteIt('Unrecognized switch = ' . "$thisarg. Ignored.\n");
}
}
}
sub FatalError
{
WriteIt($_[0]);
exit 2;
}
sub ConnectToHost
{
my $host;
my $regex;
$MCPSession = CreateObject OLE "Unisys.MCPInfo" || die "Unable to create object Unisys.MCPInfo. Error = $!";
if ($usercode)
{
$host = '\\\\' . $hostname . '\\IPC$';
# check to see if we already have this connection. If so, don't bother
my $rslt;
$rslt = `net use`; # capture output of net use command
$regex = '\\\\\\\\' . $hostname . '\\\\IPC\\$'; # have to double the number of \ because we need double for the
# regular expression
if ($rslt =~ /$regex/i)
{
#already have a connection
WriteIt("Connection to $host already exists. Usercode and/or password ignored.\n");
}
else
{
$WSHNetwork->MapNetworkDrive("",$host, 0, $usercode, $password);
# do the net use now and see if one exists. If not, we took some an error
$rslt = `net use`; # capture output of net use command
unless ($rslt =~ /$regex/i)
{
WriteIt("Unable to successfully connect to $host\n");
exit 3;
}
}
}
$MCPSession->Connect($hostname);
unless ($MCPSession->IsConnected())
{
WriteIt("Failed to connect to $hostname\n");
exit 2;
}
$MCPDCKeyin = $MCPSession->DCKeyinInterface;
}
sub ODTCommand
{
my $tnow;
my $MCPLine;
my $response;
$MCPDCKeyin->Initiate($_[0]);
$tnow = scalar localtime;
$response = $MCPDCKeyin->{Response};
WriteIt("$tnow\n" . "$response\n");
}
sub CycleODTCommands
{
my @cmds = split(/,/,$odtcommands);
while ($numcycles)
{
my @cyclecmds = @cmds;
while (@cyclecmds)
{
my $cmd=shift(@cyclecmds);
ODTCommand($cmd);
# don't delay on the last command
unless ( ($numcycles==1) && ($#cyclecmds==-1) )
{
sleep $delaysec;
}
}
if ($onceonly)
{
# no delays, just exit!
exit 0;
}
if ($numcycles>0)
{
$numcycles--;
}
# time to wait $intervalsec seconds
sleep $intervalsec;
}
}
.
- Prev by Date: Re: Keyedioii batch mode
- Next by Date: Re: Output Manager (formerly Depcon), Cold, and other Output Management Solutions
- Previous by thread: NXServices question
- Next by thread: Re: Output Manager (formerly Depcon), Cold, and other Output Management Solutions
- Index(es):
Relevant Pages
|