0

I want to call a command with a script using dash. here is my code:

#!/bin/sh
ip='172.45.0.219'
cmd1='yes yes'
cmd2="./ssh foo@$ip"
eval $cmd1 | $cmd2

when I run my script this is my output:

Pseudo-terminal will not be allocated because stdin is not a terminal.
The authenticity of host '172.45.0.219 (172.45.0.219)' can't be established.
ECDSA key fingerprint is SHA256:PpEShWXU3zQhkyAsy4Zd1Jddb2lW0ULautIdPMr8yxA.
Are you sure you want to continue connecting (yes/no)?

and waiting for a 'yes/no'. I want this script get 'yes' automatically.

I try some other ways like this:

eval echo yes | $cmd2

and get the same result. Thanks for any help.

R.A.
  • 9
  • 6
  • What overall effect should the script have? Maybe using [_expect_](https://www.tcl.tk/man/expect5.31/expect.1.html) would make more sense in this case. – user1934428 Jun 24 '20 at 13:01
  • 2
    Does [this](https://stackoverflow.com/questions/21383806/how-can-i-force-ssh-to-accept-a-new-host-fingerprint-from-the-command-line) answer your question? – user1934428 Jun 24 '20 at 13:03
  • dear @user1934428 maybe 'expect' was a good way for this question but unfortunately my device didn't support this way. I try it before but I get that 'expect' is unknown. about second comment, I must try it the day after tomorrow, because now I haven't access to my device. anyway thanks a lot. – R.A. Jun 25 '20 at 19:34
  • Silly question: Did you bother to _install_ expect? – user1934428 Jun 26 '20 at 06:52
  • dear @user1934428 In fact, I don't know how to install expect for my embedded device. Arm7 & linuxrc & sshd... I tried to find a way but it wasn't successful yet. Anyway, I thought this was not the best solution to my problem, so I tried another method. I want to authenticate the user and therefore the solution was add this 2 line before the last line. like this: ___cmd="ssh-keyscan -H $ip >> ~/.ssh/known_hosts"___ ___eval $cmd___ now there is another problem. with run this script I fall in the user command line but I need to exit from there. thanks in advance for any help – R.A. Jun 29 '20 at 11:06
  • I don't think I need to run the latest line of script, and that's my solution, but I really want to know if there's a way to fix it. To send ___exit___ from a remote command line. Thanks – R.A. Jun 29 '20 at 12:26
  • If you interact with a program, which just processes stdin, you can prepare stdin with all the commands necessary. If you need interaction with the program, you need some tool doing interaction. Since you don't want to install _expect_, you could try to use _telnet_ instead. I don't know whether this will work with ssh, as I used this with ftp only. Also you didn't say why the link I sent you in my earlier comment (June 24) does not work for you. – user1934428 Jun 29 '20 at 12:52
  • @user1934428 That link was useful for me and it was the exact response of this case. but I just need to authenticate the user, and didn't want to connect to the user. so I tried another method and share it. – R.A. Jun 30 '20 at 07:22

1 Answers1

0

In this case, the user must be authenticated and the solution is:

#!/bin/sh
ip='172.45.0.219'
cmd="ssh-keyscan -H $ip >> ~/.ssh/known_hosts"
eval $cmd

However, this is not the real answer of this question.

R.A.
  • 9
  • 6