Im trying to change the password with python on a router with a linux OS. The problem is im stuck in the input field which i've to complete with return.
My code looks like this:
root_password_bytes = subprocess.check_output(["pwgen", "-1", "32"])
root_password = root_password_bytes.decode('utf-8')
#root_password = subprocess.check_output(["pwgen", "-1", "32"])
#print(f'printing root passwd: {root_password}')
# Try 1: with decode and no quotation marks
subprocess.call([f"ssh [email protected] printf {root_password}\n{root_password}\n | passwd"], shell=True)
# error: Syntax error: "|" unexpected
# Try 2: with decode and with quotation marks
subprocess.call([f"ssh [email protected] printf '{root_password}\n{root_password}\n' | passwd"], shell=True)
# error: it tries to execute the command on my machine and not on the router
# Try 3: WITHOUT decode and no quotation marks
#subprocess.call([f"ssh [email protected] printf {root_password}\n{root_password}\n | passwd"], shell=True)
# error: Syntax error: "|" unexpected
# Try 4: WITHOUT decode and with quotation marks
#subprocess.call([f"ssh [email protected] printf '{root_password}\n{root_password}' | passwd"], shell=True)
# error: it tries to execute the command on my machine and not on the router
# passwd: Bearbeitungssfehler des Legitimierungszeichens
# Try 5: Without passwd as var
subprocess.call([f"ssh [email protected] echo 'onetwothree\nonetwothree\n' | passwd"], shell=True)
# error: it tries to execute the command on my machine and not on the router
# passwd: Bearbeitungssfehler des Legitimierungszeichens
subprocess.call([f"ssh [email protected] 'printf onetwothree\n' | passwd"], shell=True)
# Try 6: different quotation marks most success it types the first password in
# but after using new-line (\n) the pipe will be unexpected
subprocess.call([f"ssh [email protected] 'printf onetwothree123 | passwd'"], shell=True)
# so this will not work
subprocess.call([f"ssh [email protected] 'printf onetwothree123\nonetwothree123\n | passwd'"], shell=True)