Bonjour,
Jusque là, pour les besoins que j'en avais, je me suis connecté exclusivement à mon switch avec le port série. Je voulais essayer avec le port SSH, j'ai donc créé une nouvelle fonction qui ressemble de très (très) près à celle que j'utilise pour me connecter en série mais ça ne fonctionne pas

Dans les 2 cas, j'utilise plink et j'active les logs. Pour la connexion en série, pas de problème mais pour la connexion en SSH, il me trouve bien le login mais pas la suite... Le fichier de log ne se rempli pas non plus...
Voici les fonctions que j'utilise et qui viennent du fichier Plink_Wrapper trouvé ici :
https://www.autoitscript.com/forum/topi ... ntry890269
► Afficher le texte
Code : Tout sélectionner
; Connexion en série
func _Start_plink($_plink_loc,$_plinkserver)
if $_plink_loc = "" then
MsgBox(0, "Error", "Unable to open plink.exe",10)
return false
Exit
endif
if $_plinkserver = "" then
MsgBox(0, "Error", "Unable to open server",10)
Exit
return false
endif
Local $_plinkhandle = Run($_plink_loc & " -serial " & $_plinkserver,"",@SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
return $_plinkhandle
endFunc
; Connexion en SSH
func _Start_ssh($_plink_loc,$_plinkserver)
if $_plink_loc = "" then
MsgBox(0, "Error", "Unable to open plink.exe",10)
return false
Exit
endif
if $_plinkserver = "" then
MsgBox(0, "Error", "Unable to open server",10)
Exit
return false
endif
Local $_plinkhandle = Run($_plink_loc & " -ssh " & $_plinkserver,"",@SW_MAXIMIZE, $STDIN_CHILD + $STDOUT_CHILD)
return $_plinkhandle
endFunc
; Activation des logs
func _Init_plink_log($_plink_logfile)
$_plink_logfile_handle = FileOpen($_plink_logfile, 2)
; Check if file opened for writing OK
If $_plink_logfile_handle = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
return true
endfunc
; Rechercher un mot ou une phrase
func _Expect($match_text, $_plinkhandle)
local $text
local $sBuffertext
local $count = 0
local $found
local $iBegin = TimerInit()
While 1
if TimerDiff($iBegin) > $_plink_timeout then return false
if $count = 15 Then
MsgBox(0, "timeout", '"' & $match_text & '"' & " non trouvé")
Exit
EndIf
$text = StdoutRead($_plinkhandle)
$sBuffertext = $sBuffertext & $text
if $_plink_logging Then
filewriteline($_plink_logfile_handle,"**********************NEW SECTION************************")
FileWriteLine($_plink_logfile_handle, "expect : " & $match_text)
FileWriteLine($_plink_logfile_handle, "read : " & $text)
; filewriteline($_plink_logfile_handle,"**********************END SECTION************************")
endif
$count = $count+1
$found = StringRegExp($text,$match_text)
If $found = 1 Then
; If $_plink_display_messages Then MsgBox(4096, $match_text, $text, $_plink_display_message_time)
ExitLoop
Endif
sleep(1000)
Wend
return $sBuffertext
EndFunc
; Envoyer les commandes à plink
func _SayPlus($output, $_plinkhandle)
StdinWrite($_plinkhandle, $output & @CR)
endfunc
Comme vous pouvez le constater, _Start_Plink et _Start_SSH sont très proche.
Mon petit bout de programme :
► Afficher le texte
Code : Tout sélectionner
; Bout de code qui ne fonctionne pas, connexion en SSH
$handle=_Start_ssh("C:\Desktop\plink.exe","192.168.5.15")
_Init_plink_log("C:\Desktop\Log_Sw.log")
_Expect("login", $handle)
_SayPlus($sUsername, $handle)
;_Expect("password", $handle)
Sleep(1000)
_SayPlus($sPass, $handle)
Sleep(1000)
_SayPlus("show interfaces serial 0", $handle)
Sleep(4000)
_Expect("Serial 0 is up", $handle)
MsgBox(0, "Trouve", "Termine")
; Connexion en série qui fonctionne
$handle=_Start_plink("C:\Desktop\plink.exe","COM1")
_Init_plink_log("C:\Desktop\Log_Sw.log")
_Expect("login", $handle)
_SayPlus($sUsername, $handle)
_Expect("password", $handle)
_SayPlus($sPass, $handle)
_Expect("Welcome", $handle)
_SayPlus("show interfaces serial 0", $handle)
Sleep(4000)
_Expect("Serial 0 is up", $handle)
MsgBox(0, "Trouve", "Termine")
Lorsque je me connecte en SSH via l'invité de commande et en faisant appel à Plink, ça fonctionne très bien. Pour tester, j'ai mis l'attente du mot "password" en commentaire, ajouté des sleep mais il la suite n'est pas lue non plus... En lançant Putty et en lançant une session en série, je vois bien qu'une connexion s’établit sans erreur mais il n'y a rien qui s'écrit dans mon fichier de log... Même pas "login" alors qu'il l'a trouvé...
Pourriez-vous m'aider svp ?
