Automatic input "yes" in a shell script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Automatic input "yes" in a shell script
# 1  
Old 10-06-2014
Linux Automatic input "yes" in a shell script

Hi All,

I need a favour.

I have a file called "redhat_servers.txt" containing some server names line by line.

When I try to ssh to each server, and I have already done with ssh key-gen stuff. Now, for first time if I do ssh .. I need to type yes I have more than 400 servers...it will take long time to ssh to each server and type yes

I need to write a script for this.

redhat_servers.txt file looks like this

Code:
sxs1
sxs2
sxs3
-
-
-
sxs109

Please help me, how can I do this in script.

Thanks
Siva

Last edited by rbatte1; 10-06-2014 at 10:42 AM.. Reason: Added CODE & ICODE tags and tidied up grammar, spelling and capital letters
# 2  
Old 10-06-2014
You leave us guessing why you have to enter "yes". Is it in response to the question
Code:
The authenticity of host 'nnn.nnn.nnn.nnn' can't be established.
RSA key fingerprint is xx:xx:xx:xx:....
Are you sure you want to continue connecting (yes/no)?

Then you need those servers' entries in .ssh/known_hosts, and the question is gone...
# 3  
Old 10-06-2014
Hello Siva,

You can use expect script for same. Following may help.

Code:
cat test.ksh
while read line
do
 ./ssh_test.ksh test_user@"$line"
done < "server_list"

Where ssh_test.ksh is the expect script.
Code:
cat ssh_test.ksh
#!/usr/bin/expect  #Usage sshsudologin.expect <host> <ssh user> <ssh password> 
set timeout 60   
spawn ssh [lindex $argv 1]@[lindex $argv 0]   
expect "yes/no" {      
send "yes\r"    
}   
interact

So in input file server_list you can provide all servers names and while running ssh_test.ksh script it will one by one do a ssh to all the servers present in list file and will send yes to all the servers during ssh. You can change it as per your need too.

NOTE: As per your post you have done key gen already so it is only to enter yes during ssh.

Thanks,
R. Singh

Last edited by rbatte1; 10-06-2014 at 10:50 AM.. Reason: Adding icode tags, RBATTE1 splitting CODE block
# 4  
Old 10-06-2014
One could use:
' a programs own's -y toggle' only where applicable, eg: yum update -y
Does not apply to ssh, but might for other commands - see their -h or --help output.

But also, as root: (using fdisk, since you didnt show what you tried so far)
Code:
fdisk /dev/sda << EOF
?
i
1
q
EOF

(question of my own: is this a here-doc thing?)

Hope this helps

Last edited by sea; 10-06-2014 at 09:48 AM..
# 5  
Old 10-06-2014
Quote:
Originally Posted by sea
(question of my own: is this a here-doc thing?)

Hope this helps
You cannot answer security questions with a here-document, it demands a terminal.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

How to fix this "Input is not UTF-8" while executing ksh script?

Hi, I have an automated script which have set of sqls but when i am trying to execute the automated script by using nohup command, it is throwing an error like "Input is not UTF-8" . And when i digged in to it, i am getting some "Â" character in the shell script. How to avoid this!? Thanks. (1 Reply)
Discussion started by: Samah
1 Replies

3. UNIX for Dummies Questions & Answers

Using "mailx" command to read "to" and "cc" email addreses from input file

How to use "mailx" command to do e-mail reading the input file containing email address, where column 1 has name and column 2 containing “To” e-mail address and column 3 contains “cc” e-mail address to include with same email. Sample input file, email.txt Below is an sample code where... (2 Replies)
Discussion started by: asjaiswal
2 Replies

4. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

5. Shell Programming and Scripting

Suppressing the automatic output of "script"

Is there a way to suppress the output that script command displays - "Script command started..." (4 Replies)
Discussion started by: ggayathri
4 Replies

6. Shell Programming and Scripting

Command Character size limit in the "sh" and "bourne" shell

Hi!!.. I would like to know what is maximum character size for a command in the "sh" or "bourne" shell? Thanks in advance.. Roshan. (1 Reply)
Discussion started by: Roshan1286
1 Replies

7. Shell Programming and Scripting

Manipulating input into the shell "read" command

Hi All I have a migration program that creates directories based on dates, e.g 20090714 20090812 etc.. Based on their requirements, the user will select the directory they want to perform an action on. Currently, this is a snippet of the code I use no_of_versions=`ls | wc -l` if... (2 Replies)
Discussion started by: kingpin2502
2 Replies

8. AIX

"too big" and "not enough memory" errors in shell script

Hi, This is odd, however here goes. There are several shell scripts that run in our production environment AIX 595 LPAR m/c, which has sufficient memory 14GB (physical memory) and horsepower 5CPUs. However from time to time we get the following errors in these shell scripts. The time when these... (11 Replies)
Discussion started by: jerardfjay
11 Replies

9. Shell Programming and Scripting

check input = "empty" and "numeric"

Hi how to check input is "empty" and "numeric" in ksh? e.g: ./myscript.ksh k output show: invalid number input ./myscript.ksh output show: no input ./myscript.ksh 10 output show: input is numeric (6 Replies)
Discussion started by: geoffry
6 Replies

10. UNIX for Dummies Questions & Answers

No utpmx entry: you must exec "login" from lowest level "shell"

Hi I have installed solaris 10 on an intel machine. Logged in as root. In CDE, i open terminal session, type login alex (normal user account) and password and i get this message No utpmx entry: you must exec "login" from lowest level "shell" :confused: What i want is: open various... (0 Replies)
Discussion started by: peterpan
0 Replies
Login or Register to Ask a Question