can you provide me expect script if possible??
Main Topics
Browse All TopicsIn below script i want to take username & server login password from txt file , give me solutions for creating them.
REMOTESERVER="serverA serverB serverC"
export REMOTESERVER
for server in $REMOTESERVER
do
echo "$server"
echo YOU ARE LOGIN AS username IN "$server"
ssh -v username@"$server" -C "/bin/ksh -c \'/home/test.ksh;exit '"
done
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Here's an example automatically generated by autoexpect.
#!/usr/bin/expect -f
#
# This Expect script was generated by autoexpect on Tue Mar 18 15:38:55 2003
# Expect and autoexpect were both written by Don Libes, NIST.
#
# Note that autoexpect does not guarantee a working script. It
# necessarily has to guess about certain things. Two reasons a script
# might fail are:
#
# 1) timing - A surprising number of programs (rn, ksh, zsh, telnet,
# etc.) and devices discard or ignore keystrokes that arrive "too
# quickly" after prompts. If you find your new script hanging up at
# one spot, try adding a short sleep just before the previous send.
# Setting "force_conservative" to 1 (see below) makes Expect do this
# automatically - pausing briefly before sending each character. This
# pacifies every program I know of. The -c flag makes the script do
# this in the first place. The -C flag allows you to define a
# character to toggle this mode off and on.
set force_conservative 0 ;# set to 1 to force conservative mode even if
;# script wasn't run conservatively originally
if {$force_conservative} {
set send_slow {1 .1}
proc send {ignore arg} {
sleep .1
exp_send -s -- $arg
}
}
#
# 2) differing output - Some programs produce different output each time
# they run. The "date" command is an obvious example. Another is
# ftp, if it produces throughput statistics at the end of a file
# transfer. If this causes a problem, delete these patterns or replace
# them with wildcards. An alternative is to use the -p flag (for
# "prompt") which makes Expect only look for the last line of output
# (i.e., the prompt). The -P flag allows you to define a character to
# toggle this mode off and on.
#
# Read the man page for more info.
#
# -Don
#set DO_TASK "wget ftp://172.16.0.4/pub/tests
if { "x$argv" == "x" } {
send_user "\nPlease specify command to run.\r\n"
exit 1 }
catch {set DO_TASK "$argv\r"}
regsub -all {\{} $DO_TASK {} DO_TASK
regsub -all {\}} $DO_TASK {} DO_TASK
if { "x$DO_TASK" == "x" } {
send_user "\nSorry, DO_TASK died.\r\n"
exit 1 }
set timeout -1
spawn $env(SHELL)
match_max 100000
expect "*\]\$ "
send -- "ssh root@172.32.0.243\r"
expect {
"The authenticity of host '172.32.0.243 (172.32.0.243)' can't be established.\r
RSA key fingerprint is *.\r
Are you sure you want to continue connecting (yes/no)? " {
send -- "yes\r"
expect "yes\r
Warning: Permanently added '172.32.0.243' (RSA) to the list of known hosts.\r\r"
expect {
"root@172.32.0.243's password: " {
send -- "password\r"
expect "Last login: *\r\r
*root\]# "
send "wget ftp://172.16.0.4/pub/tests
expect "*root\]# "
send -- "$DO_TASK"
expect "*root\]# "
send -- ""
expect "logout\r
*Connection to 172.32.0.243 closed.\r\r
*\]\$ "
send -- ""
expect eof
} "Last login: *\r\r
*root\]# " {
send -- "$DO_TASK"
expect "*root\]# "
send -- ""
expect "logout\r
*Connection to 172.32.0.243 closed.\r\r
*\]\$ "
send -- ""
expect eof
}
}
} "root@172.32.0.243's password:" {
send -- "password\r"
expect "Last login: *\r\r
*root\]# "
send -- "$DO_TASK"
expect "*root\]# "
send -- ""
expect "logout\r
*Connection to 172.32.0.243 closed.\r\r
*\]\$ "
send -- ""
expect eof
} "Last login: *root\]# " {
send -- "$DO_TASK"
expect "*root\]# "
send -- ""
expect "logout\r
*Connection to 172.32.0.243 closed.\r\r
*\]\$ "
send -- ""
expect eof
} "Host key verification failed." {
send -- "cat ~/.ssh/known_hosts | grep -v 172.32.0.243 > ~/.ssh/known_hosts1; mv ~/.ssh/known_hosts1 ~/.ssh/known_hosts; ssh root@172.32.0.243\r"
exp_continue
}
}
Business Accounts
Answer for Membership
by: TintinPosted on 2007-09-28 at 14:40:27ID: 19981986
You should either set up ssh keys or you will need to use an expect script (which defeats the purpose of using ssh in the first place)