Hi Sharon:

           Thank you for your so detailed info. I will try this. Thank you very 
much.

BRs
William

From: Sharon Lucas [mailto:luc...@us.ibm.com]
Sent: 2011年7月27日 2:48
To: Bai, William
Cc: staf-users@lists.sourceforge.net
Subject: Re: [staf-users] how to deal with command like top in STAX

You can run top (or probably seagull) as follows using xterm for the shell and 
exporting the display.  In this example I'm starting "top" on a Linux machine 
(staf1e) from a Winodws machine.  This example also stops the process using its 
STAF handle.   You can do the same thing via a STAX job.:

C:\>STAF staf1e PROCESS START SHELL "xterm -title %T -e /bin/sh -c %X" COMMAND 
"top" TITLE "top" ENV "DISPLAY=:0.0"
Response
--------
2878

C:\>STAF staf1e PROCESS LIST
Response
--------
Handle Command Start Date-Time   End Date-Time Return Code
------ ------- ----------------- ------------- -----------
2878   top     20110726-12:30:43 <None>        <None>


C:\>STAF staf1e PROCESS STOP HANDLE 2878
Response
--------


C:\>STAF staf1e PROCESS LIST
Response
--------
Handle Command Start Date-Time   End Date-Time     Return Code
------ ------- ----------------- ----------------- -----------
2878   top     20110726-12:30:43 20110726-12:31:11 9


C:\>STAF staf1e PROCESS FREE HANDLE 2878
Response
--------


C:\>STAF staf1e PROCESS LIST
Response
--------


C:\>

Or, note that you can run top using its -b (batch mode) option in which case 
then you don't need to use xterm or export the display to run it.  I'm not 
familiar with seagull but perhaps it has a similar option.  For example:

C:\>STAF staf1e PROCESS START SHELL COMMAND "top -b"
Response
--------
2901


C:\>STAF staf1e PROCESS STOP HANDLE 2901
Response
--------


C:\>

Here's a sample STAX job that uses a <stafcmd> to submit a PROCESS START 
request without the WAIT option to start the top command using xterm and export 
the display, and returns the STAF process handle for top in the result (since 
it did not wait for top to complete),  Then it delays a while and submits a 
PROCESS STOP HANDLE request to stop top.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>

<defaultcall function="Main"/>

<function name="Main">
  <sequence>

    <script>
      machine='staf1e'  # Replace with your machine host name or IP address
      command = 'top'
      title = 'top'
      # Note: Must escape a % with another % so that Python does not think it 
is a formatting character
      request = 'START SHELL "xterm -title %%T -e /bin/sh -c %%X" COMMAND "%s" 
TITLE "%s" ENV "DISPLAY=:0.0"' % (command, title)
      waitTime = '5s'
    </script>

    <log message="1">'Starting top...'</log>

    <stafcmd name="'Start top'">
      <location>machine</location>
      <service>'PROCESS'</service>
      <request>request</request>
    </stafcmd>

    <if expr="RC == 0">
      <script>processHandle = STAFResult</script>
      <else>
        <sequence>
          <log message="1">
            'Error running top.  RC: %s, STAFResult: %s' % (RC, STAFResult)
          </log>
          <terminate/>
        </sequence>
      </else>
    </if>

    <!-- Delay while top runs -->
    <stafcmd name="'Delay for %s' % (waitTime)">
      <location>'local'</location>
      <service>'DELAY'</service>
      <request>'DELAY %s' % (waitTime)</request>
    </stafcmd>

    <log message="1">'top is done after running for %s' % (waitTime)</log>

    <stafcmd name="'Stop the process'">
      <location>machine</location>
      <service>'PROCESS'</service>
      <request>'STOP HANDLE %s' % (processHandle)</request>
    </stafcmd>

    <if expr="RC == 0">
      <log message="1">'Stopped process handle %s' % (processHandle)</log>
      <else>
        <log message="1">
          'Error stopping process handle %s' % (processHandle)
        </log>
      </else>
    </if>

    <stafcmd name="'Free the process handle'">
      <location>machine</location>
      <service>'PROCESS'</service>
      <request>'FREE HANDLE %s' % (processHandle)</request>
    </stafcmd>

  </sequence>
</function>

</stax>

Here's another sample STAX job that runs the top command on a remote a Linux 
machine using xterm and exporting the display.  It uses a timer element to run 
the top command for a specified duration and then gets top sdtout output.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE stax SYSTEM "stax.dtd">
<stax>

<defaultcall function="Main"/>

<function name="Main">
  <sequence>

    <script>
      machine='staf1e'  # Replace with your machine host name or IP address
      duration = '10s'  # Duration to run top
    </script>

    <log message="1">'Starting top...'</log>

    <timer duration="duration">
      <sequence>

        <process name="'Run top'">
          <location>machine</location>
          <command mode="'shell'" shell="'xterm -title %T -e /bin/sh -c 
%X'">'top'</command>
          <title>'top'</title>
          <env>'DISPLAY=:0.0'</env>
          <stdout>'/tmp/top.out'</stdout>
          <stderr>'/tmp/top.err'</stderr>
          <returnstderr/>
        </process>

        <if expr="RC != 0">
          <log message="1">
            'Error running top.  RC: %s, STAFResult: %s, Stderr: %s' % (RC, 
STAFResult, STAXResult)
          </log>
        </if>

      </sequence>
    </timer>

    <log message="1">'top is done after running for %s' % (duration)</log>

    <!-- Get the contents of top's stdout.
         If you don't want top's stdout output, don't do this and remove the
         stdout element in the above process element. -->

    <stafcmd name="'Get top stdout'">
      <location>machine</location>
      <service>'FS'</service>
      <request>'GET FILE /tmp/top.out'</request>
    </stafcmd>

    <if expr="RC == 0">
      <log message="1">'Output from top:\n%s' % (STAFResult)</log>
      <else>
        <log message="1">
          'Error getting top stdout file.  RC: %s, Result: %s' % (RC, 
STAFResult)
        </log>
      </else>
    </if>

  </sequence>
</function>

</stax>

--------------------------------------------------------------
Sharon Lucas
IBM Austin,   luc...@us.ibm.com
(512) 286-7313 or Tieline 363-7313




From:        "Bai, William" <william....@tekelec.com>
To:        "staf-users@lists.sourceforge.net" <staf-users@lists.sourceforge.net>
Date:        07/26/2011 11:39 AM
Subject:        [staf-users] how to deal with command like top in STAX
________________________________



Hi:

       I use STAX to start up seagull to test diameter protocol. But seagull 
will keep flushing the screen and output the result. When I use STAX to start 
seagull, it reports keybaord error. And I tried "top" command to see whether 
STAX could start "top" frontend, and it also reports error. Though I do not 
need the realtime monitoring result of seagull output on the screen, but I hope 
to find a way to start up seagull and stop them.
     Though I could put seagull to run in the background, but I could not stop 
that by terminate the job on STAX right? Could you kindly tell me how to deal 
with the commands like seagull or "top" which needs to reflushing the screen 
again and again, if let the process run in frontend, or how to stop them in 
STAX, if let them run in background. Thank you in advance.

BRs
William------------------------------------------------------------------------------
Magic Quadrant for Content-Aware Data Loss Prevention
Research study explores the data loss prevention market. Includes in-depth
analysis on the changes within the DLP market, and the criteria used to
evaluate the strengths and weaknesses of these DLP solutions.
http://www.accelacomm.com/jaw/sfnl/114/51385063/_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users
------------------------------------------------------------------------------
Got Input?   Slashdot Needs You.
Take our quick survey online.  Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
staf-users mailing list
staf-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/staf-users

Reply via email to