Does shell script return code run from PuTTY to the calling batch file?

I would like to ask a question about how to use PuTTY and control its return values. My setup is this.

Here is a file xxxxx.batthat contains a PuTTY call with an ssh connection in the following cases:

putty.ext ssh 10.10.10.10 -l xxxx -pw yyyy -t -m wintest.txt

The file wintest.txtcontains:

echo "wintest.txt: Before execute..."

/home/tede/n55115/PD/winlinux/RUN.lintest.bsh

echo "wintest.txt: After execute..."
echo $?

The file lintest.bshcontains various commands, which interests me in order to be able to capture the return value of a specific command in the .bsh file and call this value from the bat file to add it to the if loop with a warning, i.e. if $?(or %ERRORLEVEL- I don't know what will work) thenBLABLA

, , , , - .bat, .

+4
1

-, PuTTY , Plink ( PuTTY).

Plink .

script ( echo $?) :

@echo off

plink.exe putty.ext ssh 10.10.10.10 -l xxxx -pw yyyy -t -m wintest.txt > output.txt 2>&1

for /F "delims=" %%a in (output.txt) do (
   echo %%a
   set "SHELL_EXIT_CODE=%%a"
)

if %SHELL_EXIT_CODE% gtr 0 (
   echo Error %SHELL_EXIT_CODE%
) else (
   echo Success
)

, , script, , ( echo):

echo "wintest.txt: Before execute..."

/home/tede/n55115/PD/winlinux/RUN.lintest.bsh
EXIT_CODE=$?

echo "wintest.txt: After execute..."
echo $EXIT_CODE
+3

Source: https://habr.com/ru/post/1614737/


All Articles