Script Out Telnet Session and Issue a DB2 RUNSTATS Command

  • Does anyone know how to script out a telnet session?  Here's what I have:

    In a DTS package, I have a process that drops/creates a table, populates it, adds an index and then issues a command that updates the statistics on the table.  The problem is that all of these commands are issued against a DB2 database connection and the update statistics command is actually a DB2 Utility (RUNSTATS) that can only be executed at a DB2 command prompt because it is a utility, not a SQL statement. 

    My thought is if I could create a script that would open a telnet session, I could issue the command from there and then move on in my process.  So basically, I'm looking for something similar to the ftp command where you specify the commands in a file and then point to the file using the -s parameter...

    ftp [-s: filename] [hostname]

    where -s: filename specifies a text file containing ftp commands; the commands automatically run after ftp starts.

    Is this possible to create a script that controls a telnet session?

    TIA -- Brian

  • You can maybe try the following as the basis for a DTS activex script that run a telnet session.

    Sorry about the dodgy "sleep" functionality.  It works on this here XP host, and it's the only way I could think of implementing a wait in a DTS script.

    '**********************************************************************

    '  Visual Basic ActiveX Script

    '************************************************************************

    Function Main()

     Main = DTSTaskExecResult_Success

            set wshshell = createobject("wscript.shell")

            set sleeper = createobject("wscript.shell")

            wshshell.run "telnet -a localhost -f telnet.log"

            sleeper.run "sleep 5", 7,true

            wshshell.sendkeys "dir"

            sleeper.run "sleep 2", 7,true

            wshshell.sendkeys "~"

            sleeper.run "sleep 1", 7,true

            wshshell.sendkeys "exit"

            sleeper.run "sleep 2", 7,true

            wshshell.sendkeys "~"

            sleeper.run "sleep 2", 7,true

            wshshell.sendkeys "~"

            set wshshell = nothing

            set sleeper = nothing

    End Function


    Cheers,
    - Mark

  • why don't you just use the rsh (remote shell) command to run the routine on the remote host?

    rsh

    Runs commands on remote hosts running the RSH service.

    RSH host [-l username] [-n] command

      host            Specifies the remote host on which to run command.

      -l username     Specifies the user name to use on the remote host. If

                      omitted, the logged on user name is used.

      -n              Redirects the input of RSH to NULL.

      command         Specifies the command to run.

     

    just a thought,

    -Michael

  • Please excuse my ignorance concerning telnet and rsh.

    Question on both of the suggestions:  How do you specify the password to log into the remote server?  When you open a telnet session, you normally have to specify your username and then provide your password.  How is this accomplished with these suggestions?

    Also, concerning the rsh suggestion, is the "command" a single command or can I issue multiple commands at once or point to a file with multiple commands?  Once I have successfully logged in, I would want to issue a cd\ command and then the db2 command "RUNSTATS".

    TIA -- Brian

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply