Wednesday, November 21, 2007

LOG ME IN....!

This article just illustrates the use of the expect command used for automatic logging to a remote machine
without using the complex ssh key pair exchange and all...!
Make sure you have the expect package installed in your machine...

lets try for telnet login...
make a file by name telnetme
$vi telnetme

#!/usr/bin/expect
eval spawn telnet 10.0.0.27
set timeout 30
expect login:
send "username\r"
expect password:
send "password\r"
interact

Now set execute permission to the script and copy it to any of the directories in your PATH variable

For SSH Login theres a little change...

I am here making a file by nane sshme

$vi sshme

#!/usr/bin/expect
eval spawn ssh 10.0.0.27
set timeout 30
expect password:
send "password\r"
interact

NOTE: change the italicised strings with appropriate username and password
It is recommended that you give read permission only to the user who is using this script , otherwise all users could read the plain password entered

PS: Please extend the features of expect if someone knows it...

1 comment:

Shyju G said...

Sir,inspired by ur blog i have also started a blog at http://shyjug.blogspot.com .

please suggest corrections....
Shyju G (i met u wen i came for my RHCE Exam at nascent...hope u remember ;) )