How to run the script with out any interruption ?

Hi ,

  Loggin to another host using the below command in my shell script
 
ssh-keygen > /dev/null
ssh-copy-id -i ~/.ssh/id_rsa.pub
 My problem is , the second commmand expecting a user input 

Eg :

Press Enter for below three questions and issue your password
Enter file in which to save the key (/home/v45542/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):

   Every time I have to press enter for these three question whenever I run the script.  I want to skip or it should automatically skip this three questions. Please help in this . I am new to this thread

You can use Expect, which is very popular in many system.
I google here some stuff:

oreilly.com/catalog/expect/chapter/ch03.html
bash.cyberciti.biz/security/expect-ssh-login-script
code.seanodonnell.com/?id=21

Thanks a lot for the reply. But I am not sure how to implement this with my requirment. Can yopu help me out ?

Hi,
you can pass Enter like this too

echo |sh script.sh

a simple echo will return new line

thanks,
venkat

if [ $# != 3 ]
then
        echo "Syntax wrong : Correct Syntax is ./wrapper.sh <client_name> <start_time> <end_time>"
        exit
fi
start_time=$2
end_time=$3
yy=`echo $2 | cut -c 3-4`
mm=`echo $2 | cut -c 6-7`
dd=`echo $2 | cut -c 9-10`
start_hr=`echo $2 | cut -c 12-13`
end_hr=`echo $3 | cut -c 12-13`
var=`cat $1`
IFSsave="$IFS"
IFS=,
vars=($var)
IFS="$IFSsave"
quote_startdate="\"$2\""
quote_enddate="\"$3\""
echo "Press Enter for below three questions and issue your password"
ssh-keygen > /dev/null
ssh-copy-id -i ~/.ssh/id_rsa.pub ${vars[0]} > /dev/null 2&>1
for (( i=0; i < ${#vars[@]}; i++ ))
do
ssh ${vars}
#"echo Executing script for host; hostname; cd /auto/users-03/p531354/martrefresh; echo Current Directory; pwd ; *running ruby script here* "
done
rm ~/.ssh/authorized_keys ~/.ssh/id_rsa ~/.ssh/id_rsa.pub

Hi ,
Please find the above code.. echo | sh wrapper.sh param... Not working here
vars is nothing but the hostname

hi,
i think this is the place where you need to keep echo /pass enter

echo |ssh-keygen > /dev/null
echo |ssh-copy-id -i ~/.ssh/id_rsa.pub ${vars[0]} > /dev/null 2&>1
for (( i=0; i < ${#vars[@]}; i++ ))
do
echo |ssh ${vars}
#"echo Executing script for host; hostname; cd /auto/users-03/p531354/martrefresh; echo Current Directory; pwd ; *running ruby script here* "
done

please point me where you need to pass enter in the script portion

thanks,
venkat

This is the line :

ssh-copy-id -i ~/.ssh/id_rsa.pub ${vars[0]} > /dev/null 2&>1

Its working for one time enter . But here i need to pass three enter ..

How to do it
Please help me out

Here is the simple code I wrote in 3 minutes to generate key automatically:

#!/usr/bin/expect

spawn /usr/bin/ssh-keygen

expect "Enter file in which to save the key" {send "\n"}
expect "Enter passphrase" {send "\n"}
expect "Enter same passphrase again" {send "\n"}

Then the output here (I type nothing)

>> ./genkey.sh
spawn /usr/bin/ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/xxx/xxxxxxx/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again: 
>>

Try your self. :slight_smile:

Hi,

use 3 echo like echo |echo|echo /*** The command *****/

thanks,
venkat

Its not workin for second and third "enters"