Search code examples
pythonpython-3.xsshputty

Pass command to KiTTY UI


I wish to automate the below task

  1. Launch KiTTY
  2. Enter username and password
  3. Login successfully
  4. Enter this below command to see the logs
tail -2000f /apps/test/good.log

I am able to achieve up to point 3 using below code

from subprocess import Popen
Popen("powershell kitty-0.73.1.1.exe [email protected] -pw YYYY")

(new KiTTY windows is opened and user is logged in successfully)

But I don't know how to pass the below command

tail -2000f /apps/test/good.log

Note: I am using Python3

I WANT THIS AUTOMATION AT UI LEVEL. I have around 5 to 6 log files to go through while testing. I don't want to open all the logs manually. So I am looking for a way to automate it.

I am using KiTTY, because it can re-connect automatically when there is any network problem.


Solution

  • KiTTY, as well as PuTTY, has -m command-line switch to provide a command for SSH "exec" channel.
    This is discussed in: Automating command/script execution using PuTTY

    KiTTY additionally has -cmd command-line switch, which (contrary to -m) simulates key strokes on SSH "shell" channel. It is an equivalent of KiTTY "Automatic Command" feature.
    See also Open command line in C# and send commands PuTTY or KiTTY


    Though if you want to automate testing, you better use a native Python SSH module, like Paramiko.