Oct-31-2022, 08:15 AM
The code should change. The previous one too.
I just showed you how you can loop over the commands and them. The moment I posted my answer though it crossed my mind that you have to connect successfully before anything else. But I was in a hurry to correct it.
So before the for loop, on a single line of code just use the subprocess module to connect to the server then you can loop.
I just showed you how you can loop over the commands and them. The moment I posted my answer though it crossed my mind that you have to connect successfully before anything else. But I was in a hurry to correct it.
So before the for loop, on a single line of code just use the subprocess module to connect to the server then you can loop.
REMOTE_ADDRESS = '192.168.1.113' proc = subprocess.run(['ssh', REMOTE_ADDRESS]) if proc.returncode == 1: # loop over commands hereA return code 0 means that the command executed successfully with no errors - or we have 0 errors literally. You are connected.