Je suis confronté à une erreur lors de l'exécution du script .au3, cela concerne des sessions ssh Putty. En effet, à partir d'un certain nombre de sessions ce message d'erreur apparait :
"array variable has incorrect number of subscripts or subscript dimension range exceeded"
Voici le morceau de code incriminé :
Code : Tout sélectionner
for $j = 1 to ubound($tempSsessions) - 1
$sessionNumber = $sessionNumber + 1
$selectedSessions[$sessionNumber] = _arraycreate($tempSessions[$j],$selectedEnvironments[$i])
nextLogonPutty.au3
► Afficher le texte
Code : Tout sélectionner
#include <array.au3>
Global $Paused
HotKeySet("{PAUSE}", "TogglePause")
HotKeySet("{ESC}", "Terminate")
$scriptName = StringLeft(@ScriptName, StringLen(@ScriptName) - 4)
$iniLocation = @ScriptDir & '\' & $scriptName & '.ini'
If not(FileExists($iniLocation)) Then
MsgBox(0, "Exception", "The configuration file could not be found: " & $iniLocation)
exit
EndIf
$puttyLocation = IniRead($iniLocation, "common", "puttyLocation", "NotFound")
$puttyUsername = IniRead($iniLocation, "common", "puttyUsername", "NotFound")
$puttyPassword = IniRead($iniLocation, "common", "puttyPassword", "NotFound")
$defaultCommands = IniRead($iniLocation, "common", "defaultCommands", "NotFound")
$commandEnter = IniRead($iniLocation, "common", "commandEnter", "NotFound")
$inputInterval = IniRead($iniLocation, "common", "inputInterval", "NotFound")
$sendKeyDelay = IniRead($iniLocation, "common", "sendKeyDelay", "NotFound")
$commanddelimiter = IniRead($iniLocation, "common", "commanddelimiter", "NotFound")
$puttyWindowTitle = IniRead($iniLocation, "common", "puttyWindowTitle", "NotFound")
$puttyWindowCheckTimeout = IniRead($iniLocation, "common", "puttyWindowCheckTimeout", "NotFound")
$selectedSessions = _arraycreate("","","","","","","","","","","")
$selectedSessionCommands = _arraycreate("","","","","","","","","","","")
$commands = _arraycreate("","","","","","","","","","","")
$selectedEnvironments = IniRead($iniLocation, "launch", "selectedEnvironments", "NotFound")
$selectedSessions = _getsessions($selectedEnvironments)
; ------------------------------------------------------------------------------
; MAIN
; ------------------------------------------------------------------------------
$selectedSessionCommands = _getSelectedSessionCommands($selectedSessions)
$commands = _getCommands($selectedSessions)
Opt("SendKeyDelay", $sendKeyDelay)
for $i = 1 to UBound($selectedSessionCommands) - 1
Run($puttyLocation, "", @SW_MAXIMIZE)
if not (FileExists($puttyLocation)) Then
msgbox(0,"","The putty exe could not be found at location " & $puttyLocation)
Exit
EndIf
if WinWaitActive($puttyWindowTitle, "", $puttyWindowCheckTimeout) then
sleep(1000)
send ($defaultCommands)
Send ($selectedSessionCommands[$i])
send($commandEnter)
sleep($inputInterval)
if not($puttyUsername) = "" Then
Send ($puttyUsername)
send ($commandEnter)
sleep($inputInterval)
EndIf
sleep($inputInterval)
if not($puttyPassword) = "" Then
Send ($puttyPassword)
send ($commandEnter)
sleep($inputInterval)
EndIf
$commandArray = $commands[$i]
for $commandId = 1 to Ubound($commandArray) - 1
send($commandArray[$commandId])
send($commandEnter)
Next
Else
msgbox(0,"","The putty window with title " & $puttyWindowTitle & " could not be find within the foreseen timeframe")
Exit
EndIf
next
; ------------------------------------------------------------------------------
; FUNCTIONS
; ------------------------------------------------------------------------------
Func _getSelectedSessionCommands($selectedSessions)
redim $selectedSessionCommands [ubound($selectedSessions)]
$selectedSessionCommands[0] = ubound($selectedSessions)
for $i = 1 to ubound($selectedSessions) - 1
$session = $selectedSessions[$i]
$selectedSessionCommands[$i] = IniRead($iniLocation, "sessions", $session[0], "NotFound")
if $selectedSessionCommands[$i] == "NotFound" Then
MsgBox(0, "Exception", "Could not find session " & $selectedSessionCommands[$i] & " in the configuration file")
exit
EndIf
Next
return $selectedSessionCommands
EndFunc
Func _getsessions($selectedEnvironments)
$selectedEnvironments = StringSplit($selectedEnvironments, ",")
$sessionNumber = 0
for $i = 1 to ubound($selectedEnvironments) - 1
$tempSessions = IniRead($iniLocation, "environments", $selectedEnvironments[$i], "NotFound")
if $tempSessions == "NotFound" Then
MsgBox(0, "Exception", "Could not find environment " & $selectedEnvironments[$i] & " in the configuration file")
exit
EndIf
$tempSessions = StringSplit($tempSessions, ",")
for $j = 1 to ubound($tempSessions) - 14
$sessionNumber = $sessionNumber + 1
$selectedSessions[$sessionNumber] = _arraycreate($tempSessions[$j],$selectedEnvironments[$i])
next
Next
redim $selectedSessions [$sessionNumber + 1]
$selectedSessions[0] = ubound($selectedSessions)
return $selectedSessions
EndFunc
Func _getCommands($selectedSessions)
redim $commands [ubound($selectedSessions)]
$commands[0] = ubound($selectedSessions)
for $i = 1 to ubound($selectedSessions) - 1
$session = $selectedSessions[$i]
$commandString = IniRead($iniLocation, "commands", $session[1], "NotFound")
$commands[$i] = stringsplit($commandString, $commanddelimiter)
if $selectedSessionCommands[$i] == "NotFound" Then
MsgBox(0, "Exception", "Could not find command " & $commands[$i] & " in the configuration file")
exit
EndIf
Next
return $commands
EndFunc
Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc
Func Terminate()
Exit 0
EndFunc► Afficher le texte
Code : Tout sélectionner
[launch]
selectedEnvironments=PROD
[common]
puttyLocation=C:\Documents and Settings\admin\Bureau\putty.exe
puttyUsername=admin
puttyPassword=admin
puttyWindowTitle=PuTTY Configuration
puttyWindowCheckTimeout=5
defaultCommands={TAB 4}{DOWN 1}
commandEnter={ENTER}
commanddelimiter=;
inputInterval=1000
sendKeyDelay=45
[environments]
PROD=199,200,201,202,203,204,205,206,207,208,209,210,211,212,213
[sessions]
199={DOWN 1}
200={DOWN 2}
201={DOWN 3}
202={DOWN 4}
203={DOWN 5}
204={DOWN 6}
205={DOWN 7}
206={DOWN 8}
207={DOWN 9}
208={DOWN 10}
209={DOWN 11}
210={DOWN 12}
211={DOWN 13}
212={DOWN 14}
213={DOWN 15}
PROD=su;admin;poweroff;exit;exit;
Merci par avance pour toute l'aide que vous pourrez m'apporter



