Passing password for ssh in Script

I want to do following 2 commands via script:

1) eval `ssh-agent`2) ssh-add /export/home/sufuser/.ssh/id_rsa When asked for passphrase enter "passwordpassword1234

but whenever I run the script it stucks after "ssh-add /export/home/sufuser/.ssh/id_rsa" command and asks fro password
although I have given password in script its not taking it and asking to input [assword mannually , but if I am inputtting the password manually its not working .....
If i do thses steps manually 1 bye 1 ... everything works very fine . . .

Need your help in prepatation of such a script which will take ssh password via script

Hi,

explore 'expect' utility to manage non-interactive ssh session.

A barebone script in expect may look something like this:

#!/usr/bin/expect

#   get parameters from command arguments
set host [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]

#   set remote host shell prompt to correct value
set shell_prompt "~]# "

#   spawn ssh session to host
spawn ssh $user@$host

expect {
          "assword:" {
             send -s "$password\r"
             #the expect command will now return
          }
}

expect {
        "$shell_prompt"
}

sleep 1
send -s -- "YOUR COMMAND HERE\r"

expect {
        "$shell_prompt"
}

#   close connection to remote host
send -s -- "exit\r"
send -s -- "\r"

#   end of expect script
exit 0

invoke the script as usual:

$ ./myscript.expect remotehost remoteuser remotepassword

see ya
fra

Hi fra, thanks for your prompt reply.
can you please give me exact script with following requirment
1)eval `ssh-agent`
2) ssh-add /export/home/sufuser/.ssh/id_rsa When asked for passphrase enter "passwordpassword1234"
3) dumpsubscribers user root outputDir /ISS/dump/

All above three stpes should be executed in sequence

Thanks,
Yogesh

Hi,

may you please clarify what you're actually trying to do? I mean, explain the objective of the actions you'd like to perform on the remote server (i.e: first transfer of files, second execution of remote commands etc.)

see ya
fra

Hi Fra.

Actually I am trying to ssh into my database by follwoing 2 commands:
1)eval `ssh-agent`
2) ssh-add /export/home/sufuser/.ssh/id_rsa

and then running following comamnd to dump data to drirectory /ISS/dump/ by command

dumpsubscribers user root outputDir /ISS/dump/

This command will dump all data in *.zip file format to /ISS/dump/ .

I want to automize this by preparing 1 script and adding it to crontab.

-Yogesh