1

I have a command line Python program which takes user input and adds it to a config file. When run it prompts the user to enter one config value at a time. The user enters the value and hits enter to get prompted for the next value. Examples of these values are as follows:

Please enter configured host IP:
Please enter the username for the account:
Please enter password for the user:

This program runs on a remote server and is executed as one part of a manual process. I'm trying to automate this process and am using the paramiko library to run this command. I use exec_command to run it. Can I send the values that the program prompts for using paramiko and if so, how?

runnerpaul
  • 5,942
  • 8
  • 49
  • 118

1 Answers1

0

This is what I did:

ssh_stdin, ssh_stdout, ssh_stderr = self.ssh.exec_command(
    'sudo python3 {}initialSetup.py'.format(self.backup_directory),
    60)
ssh_stdin.write('1.2.3.4\n')
ssh_stdin.write('username\n')
ssh_stdin.write('password\n')

See here for details.

runnerpaul
  • 5,942
  • 8
  • 49
  • 118
  • Please, instead of posting a duplicate answer, accept that your question is duplicate and consider upvoting the duplicate question and its answers. – Martin Prikryl May 18 '20 at 17:16