Script sagt bei der Ausführung call ist syntaktisch an dieser Stelle nicht verarbeitbar.
Hi
Ich habe ein Problem mit einem Script, das einen ESXi herrunterfahren soll.
Es kommt immer "call" ist syntaktisch an dieser Stelle nicht verarbeitbar.
könnte mir da vll. jemand helfen.
Es besteht aus 2 Scripten.
1) Script
Hier das Script:
MFG Nemesis
PS: das Script ist für eine APC Smart USV für den Kostenlosen ESXi
(Ich weiß offizell wird das nicht supportet)
Ich habe ein Problem mit einem Script, das einen ESXi herrunterfahren soll.
Es kommt immer "call" ist syntaktisch an dieser Stelle nicht verarbeitbar.
könnte mir da vll. jemand helfen.
Es besteht aus 2 Scripten.
1) Script
@echo off
c:\scripts\esxi\shutdown [Hosetname oder IP] [Benutzer] [Passwort]
Hier das Script:
@echo off
REM
REM *** ESXi Shutdown Script for use with free-licensed ESXi ***
REM
REM Primarily designed to shutdown an ESXi server under UPS management software
REM control, i.e. APC PowerChute.
REM
REM Performs a graceful ESXi shutdown - note that the server will ultimately
REM be powered off after VMs are suspended or shutdown, depending on their
REM configuration. As a result, when utility power is restored, the host
REM *will not restart* itself (unless the UPS battery was completely
REM depleted and the server BIOS was appropriately configured).
REM
REM
REM Written by James Pearce (vmware communities user ID J1mbo
REM (http://communities.vmware.com/people/J1mbo?view=profile).
REM
REM Version 4 (being for use with ESXi 4)
REM - tested against ESXi 4 U1 from a Windows 2003 VM
REM - completed 09-Dec-09
REM
REM Usage: Shutdown.bat [hostname] [username] [password]
REM
REM [hostname] must be valid DNS name or an IP address
REM [username] is a user with shutdown rights, i.e. root
REM [password] is as used to connect to vSphere Client with the specificed
REM username.
REM
REM Usage is logged to shutdown.log, stored in the same directory as the script.
REM
REM Depends on supporting text files:
REM
REM - open-1.txt - Establishes the session, part 1.
REM - open-2.txt - Establishes the session, part 2.
REM
REM - auth-1.txt - Authentication request, part 1.
REM - auth-2.txt - Authentication request, part 2.
REM - auth-3.txt - Authentication request, part 3.
REM
REM - shutdown-1.txt - Shutdown request, part 1.
REM - shutdown-2.txt - Shutdown request, part 2.
REM - shutdown-3.txt - Shutdown request, part 3.
REM
REM
REM IMPORTANT: DEPENDS ON NMAP "NCAT" UTILITY BEING PRESENT AND ACCESSIBLE IN THE
REM DEFAULT SEARCH PATH.
REM
REM Free disrtibution and use permitted - but entirely at your own risk!!
REM
REM If you find it useful commerically, a bottle of ale would always be
REM welcome :)
REM
REM First ensure in correct directory as APC software might not.
REM
REM These commands change the drive and directory to where the batch file is stored,
REM for example if it's at C:\ESXI\SHUTDOWN.BAT these lines become "C:" then
REM "cd \esxi\"
%~d0
cd %~dp0
REM Log the use of the script
call :WriteLog "System shutdown called: %date% %time%"
REM Check paramters were passed in:
If %1a==a goto :ArgumentError
If %2a==a goto :ArgumentError
If %3a==a goto :ArgumentError
call :CheckHost %1
if not %hostconnectres%==found Goto :CleanUp
REM Found and could ping the host, OK to attempt the shutdown.
REM Store specified hostname or IP in file to enable the assembly of the HTTP requests.
Echo Host: %1:443 >shutdown-host.txt
set shutdown-host=%1
REM Compute length of auth frame data and write out temp files...
call :GetAuthLength %2 %3
Echo Content-Length: %content_len% > content-len.txt
REM Now assemble the files.
copy open-1.txt + shutdown-host.txt + open-2.txt open.txt > NUL
copy auth-1.txt + shutdown-host.txt + content-len.txt + auth-2.txt authenticate.txt > NUL
Echo ^<userName^>%2^</userName^>>> authenticate.txt
Echo ^<password^>%3^</password^>>> authenticate.txt
copy authenticate.txt + auth-3.txt authenticate.txt > NUL
REM Announce our presence, so that the ESXi server will expect our authentication
REM attempt.
Echo Connecting...
ncat -C -i 2s --ssl %shutdown-host% 443 < open.txt > open-res.txt
REM Check that response was HTTP/1.1 200 OK:
call :GetResponse open-res.txt
if not %httpretcode%==200 Goto :ServerNotResponding
REM next, an authentication attempt which will produce a session key:
Echo Authenticating...
ncat -C -i 2s --ssl %shutdown-host% 443 < authenticate.txt > auth-resp.txt
REM Check that response was HTTP/1.1 200 OK:
call :GetResponse auth-resp.txt
if not %httpretcode%==200 Goto :AuthenticationError
Echo Creating host shutdown task...
REM Find the key, and insert it in pre-formed request split at appropriate position...
find "vmware_soap_session" auth-resp.txt > auth-key.txt
for /f "skip=2 tokens=1,2,3,4* delims==;" %%i in (auth-key.txt) do echo %%j > auth-key.txt
copy shutdown-1.txt + shutdown-host.txt + shutdown-2.txt + auth-key.txt + shutdown-3.txt shutdown.txt > NUL
REM Send completed request to the ESXi host:
REM FOLLOWING NCAT... IS THE DANGER LINE - REM IT OUT FOR INITIAL TESTING AS IT *WILL* SHUTDOWN
REM THE SPECIFIED ESXI HOST IF AUTHENTICATION SUCCEEDED!!
ncat -C -i 2s --ssl %shutdown-host% 443 < shutdown.txt > shutdown-resp.txt
REM Check that response was HTTP/1.1 200 OK:
call :GetResponse shutdown-resp.txt
if not %httpretcode%==200 Goto :ShutdownError
REM Result was OK - Log this.
call :WriteLog "Server accepted shutdown request."
Goto :Cleanup
REM --------------------------------------------------------------------------------
REM - Supporting "sub-routines" -
REM --------------------------------------------------------------------------------
REM --------------------------------------------------------------------------------
:ArgumentError
REM script was called without three parameters
Echo.
Echo Usage: Shutdown.bat [hostname] [username] [password]
Echo.
Echo [hostname] must be valid DNS name or an IP address
Echo [username] is a user with shutdown rights, i.e. root
Echo [password] is as used to connect to vSphere Client with the specificed
Echo username.
Echo.
Echo Usage is logged to shutdown.log, stored in the same directory as the script.
Echo.
call :WriteLog "Missing parameter(s) - Usage: Shutdown.bat [hostname] [username] [password]"
Goto :End
REM --------------------------------------------------------------------------------
:CheckHost
REM Routine to determine if host is valid and online. Performs a Ping test.
REM Clear out any old files:
if exist test-connect.txt del test-connect.txt
if exist not-found.txt del not-found.txt
if exist found.txt del found.txt
if exist time-out.txt del time-out.txt
set hostconnectres=
REM Ping the host - first ping is desregarded as may time out due to arp delay:
ping %1 -n 1 > NUL
ping %1 -n 1 > test-connect.txt
REM Analyse the results and set environment variable hostconnectres:
find "could not find host" test-connect.txt > not-found.txt
find "Lost = 0" test-connect.txt > found.txt
find "Lost = 1" test-connect.txt > time-out.txt
for /f "skip=2 tokens=*" %%i in (not-found.txt) do if not a%%i==a set hostconnectres=cant_resolve
for /f "skip=2 tokens=*" %%i in (found.txt) do if not a%%i==a set hostconnectres=found
for /f "skip=2 tokens=*" %%i in (time-out.txt) do if not a%%i==a set hostconnectres=time-out
REM Clear-up temp files:
if exist test-connect.txt del test-connect.txt
if exist not-found.txt del not-found.txt
if exist found.txt del found.txt
if exist time-out.txt del time-out.txt
REM Write out results to the log:
if %hostconnectres%==cant_resolve call :WriteLog "Could not resolve specified hostname %1."
if %hostconnectres%==time-out call :WriteLog "Could not reach specified host %1: time-out."
Goto :End
REM --------------------------------------------------------------------------------
:GetAuthLength
REM Returns in environment variable content_len the length of the auth frame, based
REM on the username in %1, password in %2 + 467.
echo %1%2 > tempstr.txt
for %%a in (tempstr.txt) do set /a len=%%~za
set /a len -=3
set /a content_len = %len% + 467
if exist tempstr.txt del tempstr.txt
Goto :End
REM --------------------------------------------------------------------------------
:ServerNotResponding
call :WriteLog "ESXi Server did not accept connection attempt:"
call :WriteLog "Return code was %httpretcode%."
Goto :Cleanup
REM --------------------------------------------------------------------------------
:AuthenticationError
call :WriteLog "ESXi authentication did not succeed:"
call :WriteLog "Return code was %httpretcode%."
Goto :Cleanup
REM --------------------------------------------------------------------------------
:ShutdownError
call :WriteLog "ESXi shutdown request failed:"
call :WriteLog "Return code was %httpretcode%."
Goto :Cleanup
REM --------------------------------------------------------------------------------
:GetResponse
REM Stores the response code in return frame passed via a file specified as %1.
REM HTTP/1.1 response code (i.e. 200 for OK) is stored in %httpretcode%
set httpretcode=(no-response-from-server)
if exist response-tmp.txt del response-tmp.txt
find "HTTP/1.1" %1 > response-tmp.txt
for /f "skip=2 tokens=1,2* delims= " %%i in (response-tmp.txt) do set httpretcode=%%j
if exist response-tmp.txt del response-tmp.txt
Goto :End
REM --------------------------------------------------------------------------------
:CleanUp
call :WriteLog "---------------------------------------------------------------------------"
REM Clear up temporary text files...
if exist shutdown-host.txt del shutdown-host.txt
if exist open.txt del open.txt
if exist authenticate.txt del authenticate.txt
if exist shutdown.txt del shutdown.txt
if exist open-res.txt del open-res.txt
if exist shutdown-resp.txt del shutdown-resp.txt
if exist auth-key.txt del auth-key.txt
if exist auth-resp.txt del auth-resp.txt
if exist response-tmp.txt del response-tmp.txt
Goto :End
REM --------------------------------------------------------------------------------
:WriteLog
REM Appends the specified string to the log file and displays on screen.
echo %~1
echo %~1 >> shutdown.log
Goto :End
:End
MFG Nemesis
PS: das Script ist für eine APC Smart USV für den Kostenlosen ESXi
(Ich weiß offizell wird das nicht supportet)
Bitte markiere auch die Kommentare, die zur Lösung des Beitrags beigetragen haben
Content-ID: 170069
Url: https://administrator.de/contentid/170069
Ausgedruckt am: 21.11.2024 um 12:11 Uhr
2 Kommentare
Neuester Kommentar
Über welches call Kommando kommt er denn nicht? Da sind ja mehrere drin.
Ok, ich nehme an, Du hast keine Ahnung welches und auch keine Ahnung wie man es rausbekommt.
Also, Debugging for ...:
Als erstes, nimm mal den @echo off Befehl aus dem langen Skript raus und starte es mal in einer Kommandozeile.
Da sollte man dann eigentlich sehen, an welchem call er rausfliegt.
Und eventuell noch die Info, von welchem OS Du versuchst es auszuführen, dann muß man auch nicht soviel raten.
Ok, ich nehme an, Du hast keine Ahnung welches und auch keine Ahnung wie man es rausbekommt.
Also, Debugging for ...:
Als erstes, nimm mal den @echo off Befehl aus dem langen Skript raus und starte es mal in einer Kommandozeile.
Da sollte man dann eigentlich sehen, an welchem call er rausfliegt.
Und eventuell noch die Info, von welchem OS Du versuchst es auszuführen, dann muß man auch nicht soviel raten.