[Gambas-user] How to interrupt a process waiting for a response in non interactive application

Marc Guillaume alarch at alarch.pw
Thu Mar 24 00:20:00 CET 2022


Hello,

I am struggling with the management of a process. I want to launch a
ssh command on remote servers (more than 200 servers), connections
using an ssh key.

The server's key on which the gambas application is running is
normally deployed on the servers via ansible from another machine. 

However sometimes the ssh configuration is faulty and does not allow
ssh key connection, and ask for a password. I don't have control over
this process.

The problem occurs if the server is configured to ask for a password.
In this case the process remains blocked indefinitely. I would like to
be able to abandon it after a timeout value that I can determine in the
configuration. If the server is unknow I get the 255 error return, but
il y have accepted it's key in known_hosts an it ask for a password the
process hang.

I use such a code (simplified for explanation): 


Public sConfirmConProcess As String

Public Sub Button1_Click()

  Dim sCommande As String

  sConfirmConProcess = ""
  sCommande = "ssh -v -o ConnectTimeout=10  -p 22 -q -l root " &
  TextBox1.Text & " \"exit\";echo $?;"

  Shell sCommande Wait For Input As "ConProcess"
  If CInt(Trim(sConfirmConProcess)) = 0 Then
    print "connexion confirmée"
  Else
    print "connexion échouée ou en timeout " & sConfirmConProcess
  Endif
  
  Catch
    Print Error.Text

End

Public Sub ConProcess_Read()
  
  Dim sLine As String
    
  sLine = Read #Last, -256
  sConfirmConProcess &= sLine
  
End

Public Sub ConProcess_kill()
  
  Print "Processus terminé"
  
End

If the remote server asks for a password the process doesn't send
anything and the application remains blocked. The Read event is never
triggered. 

How to use the process to be able to stop it if it does not
answer after a given time?

Cheers,

--
Alarc'h

My configuration (I can't upgrade at this time) :
[System]
Gambas=3.14.3
OperatingSystem=Linux
Kernel=5.4.0-104-generic
Architecture=x86_64
Distribution=Ubuntu 20.04.4 LTS
Desktop=KDE5
Theme=Oxygen
Language=fr_FR.UTF-8
Memory=7749M

[Libraries]
Cairo=libcairo.so.2.11600.0
Curl=libcurl.so.4.6.0
DBus=libdbus-1.so.3.19.11
GStreamer=libgstreamer-1.0.so.0.1602.0
GTK+2=libgtk-x11-2.0.so.0.2400.32
GTK+3=libgtk-3.so.0.2404.16
OpenGL=libGL.so.1.7.0
Poppler=libpoppler.so.97.0.0
QT5=libQt5Core.so.5.12.8
SDL=libSDL-1.2.so.0.11.4
SQLite=libsqlite3.so.0.8.6

[Environment]
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
DEFAULTS_PATH=/usr/share/gconf/plasma.default.path
DESKTOP_SESSION=plasma
DISPLAY=:0
GB_GUI=gb.qt5
GPG_AGENT_INFO=/run/user/1000/gnupg/S.gpg-agent:0:1
HOME=<home>
KDE_FULL_SESSION=true
KDE_SESSION_UID=1000
KDE_SESSION_VERSION=5
LANG=fr_FR.UTF-8
LANGUAGE=fr_FR.UTF-8
LOGNAME=<user>
MANDATORY_PATH=/usr/share/gconf/plasma.mandatory.path
PAM_KWALLET5_LOGIN=/run/user/1000/kwallet5.socket
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
PWD=<home>
QT_ACCESSIBILITY=1
QT_AUTO_SCREEN_SCALE_FACTOR=0
SESSION_MANAGER=local/<hostname>:@/tmp/.ICE-unix/1027,unix/<hostname>:/tmp/.ICE-unix/1027
SHELL=/bin/bash
SHLVL=0
SSH_AGENT_PID=955
SSH_AUTH_SOCK=/tmp/ssh-hjFJjLNLg2A4/agent.911
TZ=:/etc/localtime
USER=<user>
XAUTHORITY=<home>/.Xauthority
XCURSOR_SIZE=0
XCURSOR_THEME=breeze_cursors
XDG_CONFIG_DIRS=/etc/xdg/xdg-plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings
XDG_CURRENT_DESKTOP=KDE
XDG_DATA_DIRS=/usr/share/plasma:/usr/local/share:/usr/share:/var/lib/snapd/desktop
XDG_RUNTIME_DIR=/run/user/1000
XDG_SEAT=seat0
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
XDG_SESSION_CLASS=user
XDG_SESSION_DESKTOP=KDE
XDG_SESSION_ID=3
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
XDG_SESSION_TYPE=x11
XDG_VTNR=1


More information about the User mailing list