Script to login to remote server via script

Write a script to login to remote server and store the password .

An Expect script is a interaction script written for two Channels: a sender and a receiver. One of the more popular activities to automate is an SSH session between two hosts, in which one host is the sender (local host) and the other is the receiver (remote host).

Step1. sudo yum install expect

 spawn ssh
 expect "password"
 send "redhat\r"
 expect "$"

 !/usr/bin/expect --->
To make an Expect script executable as a standalone program, you must do two things: Make the script executable, and supply the path to the script for expect . The path on my system is: /usr/bin/expect
spawn ssh  -----> spawn runs an external command from the expect script,```` In this case, ssh to a remote host (remotesystem ):
expect "password"  -----------> When you SSH to a remote system, you’re prompted for a password. This password prompt is what you “expect” from the remote system; therefore, you enter that expected response
 send "redhat\r"  ------------->From the local side, you have to enter your password at the password prompt. To send anything to the remote system it must include a hard return (\r ). Change PASSWORD to your password:
expect "$" ------------->you have to enter the expected response from the remote system, which in this case is a user prompt ($ ).

Leave a Reply

Your email address will not be published. Required fields are marked *