Alex Rivera | Logout

How to input automatically when running a shell over SSH?

Asked 2012-01-31T06:42:27.473
44

In my shell script I am running a command which is asking me for input.

How can I give the command the input it needs automatically?

For example:

$cat test.sh
ssh-copy-id tester@10.1.2.3

When running test.sh:

  • First, it will ask:

    Are you sure you want to continue connecting (yes/no)?

  • Then, it will ask me to input the password:

    tester@10.1.2.3's password:

Is there a way to input this automatically?

Edit
Report

1 Answer

19

For general command-line automation, Expect is the classic tool. Or try pexpect if you're more comfortable with Python.

Here's a similar question that suggests using Expect: Use expect in bash script to provide password to SSH command

answered 2012-01-31T06:54:19.697

Your Answer