AutoIt
AutoIt
Send a Signal to a Remote SSH Process
See more SSH Examples
Demonstrates the Chilkat Ssh.SendReqSignal method, which requests delivery of a signal to the remote process running on a channel. The first argument is the channel number and the second is the signal name. Send it after the process has started.
Background: This is the SSH equivalent of pressing Ctrl+C or running
kill — it lets a client interrupt or terminate a long-running remote command without tearing down the connection. Signal names are given without the SIG prefix (INT, TERM, KILL, and so on). Note that some servers, including common OpenSSH builds, do not implement signal delivery.Chilkat AutoIt Downloads
Local $bSuccess = False
; Demonstrates the Ssh.SendReqSignal method, which requests delivery of a signal to the remote
; process running on a channel. The 1st argument is the channel number and the 2nd is the
; signal name. Send it after the process has started.
$oSsh = ObjCreate("Chilkat.Ssh")
Local $iSshPort = 22
$bSuccess = $oSsh.Connect("ssh.example.com",$iSshPort)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Normally you would not hard-code the password in source. You should instead obtain it
; from an interactive prompt, environment variable, or a secrets vault.
Local $sPassword = "mySshPassword"
$bSuccess = $oSsh.AuthenticatePw("mySshLogin",$sPassword)
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Open a session channel. A negative return value indicates failure.
Local $iChannelNum = $oSsh.OpenSessionChannel()
If ($iChannelNum < 0) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Start a long-running command.
$bSuccess = $oSsh.SendReqExec($iChannelNum,"sleep 60")
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
; Send an interrupt signal to the remote process. The name omits the "SIG" prefix.
$bSuccess = $oSsh.SendReqSignal($iChannelNum,"INT")
If ($bSuccess = False) Then
ConsoleWrite($oSsh.LastErrorText & @CRLF)
Exit
EndIf
ConsoleWrite("Signal sent." & @CRLF)
$oSsh.Disconnect