Welcome, Guest
Username Password: Remember me

expect command in unix /linux?
(1 viewing) (1) Guest
Shell Script
  • Page:
  • 1

TOPIC: expect command in unix /linux?

expect command in unix /linux? 6 months, 1 week ago #733

  • scmuser
  • OFFLINE
  • Gold Boarder
  • scm master
  • Posts: 237
  • Points: 3429
  • Karma: 0
  • Honor Medal 2009
Hello,
I am doing a project which asks me to enter password 4 times in a row. I need to enter the same password 4 times. My target is to enter password once and apply it 4 times.
My friend told me to use "expect" command. Can you please give me a sample code to do so.

sample command :- $ ssh <user name>@<ip address>(like :ssh root@127.0.0.1)
enter <user name>'s password:

Could somebody plz tell me where the command "expect" is used. and wud appreciate if you can write a simple standalone script that uses this command. thanks

Re: expect command in unix /linux? 6 months, 1 week ago #734

  • rajeshkumar
  • OFFLINE
  • Moderator
  • I love software configuration management
  • Posts: 370
  • Points: 44589
  • Karma: 4
  • Honor Medal 2009
Hi:

Expect is a tool for automating interactive applications. While it's available on most Linux systems, you typically have to download it for other systems. Here's the expect home page:

expect.nist.gov

The most common example is automating the passwd command which is impossible from the shell:

#!/usr/local/bin/expect --
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd
# Executable only by root
set password [lindex $argv 1]
spawn /usr/bin/passwd [lindex $argv 0]
expect "password:"
send "$password\r"
expect "password:"
send "$password\r"
expect eof

# end script

An excellent book is Exploring Expect by Don Libes.
Regards,
Rajesh Kumar
Build and Release Engineer
My Blog: community.scmgalaxy.com/pg/profile/rajeshkumar
  • Page:
  • 1
Time to create page: 0.71 seconds

     
    
Home Forum