[EDITED]
It can be considered as an extension to [this question][1].
echo | command
The above command can be used to supply one 'ENTER' character to the command's first input request.
How can i supply the next 'ENTER' character to the same command in its second input request.
Please comment if any other details are required.
Am giving the specific example which i want to implement.
I need to run SSH-keyGen
commmand in my shell script.
It will ask for following inputs:
How can we pass these three inputs to the command?
I tried with,
echo -ne "\n \n"| ssh-keygen //which is passing two new lines for the first input request only.
and
echo -ne "\n"|(echo -ne "\n"|ssh-keygen)// but still no positive result
Note: Am avoiding the input file name request in the above two command, just to make the things simple
Using a Backslash. The backslash (\) is an escape character that instructs the shell not to interpret the next character. If the next character is a newline, the shell will read the statement as not having reached its end. This allows a statement to span multiple lines.
How To Run a Command Multiple Times in Bash. Wrap your statement for i in {1..n}; do someCommand; done , where n is a positive number and someCommand is any command. To access the variable (I use i but you can name it differently), you need to wrap it like this: ${i} . Execute the statement by pressing the Enter key.
You should take a look at expect:
#!/usr/bin/expect
#set timeout 10
set clientName [lindex $argv 0];
set hostName [lindex $argv 1];
set passWord [lindex $argv 2];
spawn ssh "$hostName";
expect "Password:";
send "$passWord\r";
expect "$hostName";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With