passwd bob Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
#!/usr/bin/expect spawn passwd [lindex $argv 0] set password [lindex $argv 1] expect "password:" send "$password\r" expect "password:" send "$password\r" expect eof
./exp1.exp bob 123 spawn passwd bob Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully
#!/usr/bin/expect spawn passwd [lindex $argv 0] set password [lindex $argv 1] expect "password:" send "$password\r" expect "password:" send "$password\r" expect eof
#!/usr/bin/expect
set timeout 15
expect "hi" { send "You said hi\n" } \
"hello" { send "Hello to you\n" } \
"bye" { send "Goodbye\n" } \
timeout { send "I’m fed up\nbye\n" }
I’m fed up bye
fred@merlin:$ ftp guenevere Connected to guenevere. 220 guenevere FTP server (Version wu-2.6.0(1)) Name (guenevere:fred): anonymous 331 Guest login ok, send your complete e-mail 331 address as password. Password:nobody@nowhere.com 230-Welcome, archive user anonymous@merlin ! 230- 230-The local time is: Mon Feb 12 15:18:14 2001 230- 230 Guest login ok, access restrictions apply. Remote system type is UNIX. Using binary mode to transfer files.
ftp> dir 200 PORT command successful. 150 Opening ASCII mode data connection for /bin/ls. total 20 d--x--x--x 2 0 0 4096 Aug 10 2000 bin d--x--x--x 2 0 0 4096 Aug 10 2000 etc d--x--x--x 2 0 0 4096 Aug 10 2000 lib dr-xr-xr-x 4 0 0 4096 Sep 28 22:17 pub -rw-r--r-- 1 0 0 346 Aug 10 2000 welcome.msg 226 Transfer complete. ftp> quit 221-You have transferred 0 bytes in 0 files. 221-Total traffic for this session was 1182 221-bytes in 1 transfers. 221-Thank you for using the FTP service on 221-guenevere. Goodbye.
#!/usr/bin/expect set site [lindex $argv 0] spawn ftp $site expect "Name" send "anonymous\r" expect "Password:" send "nobody@nowhere.com\r" interact
if {$count < 0} {
set total 1
}
if {$count < 5} {
puts "count is less than five"
} else {
puts "count is not less than five"
}
if {$count < 0} {
puts "count is less than zero"
} elseif {$count > 0 {
puts "count is greater than zero"
} else {
puts "count is equal to zero"
}
#!/usr/bin/expect
set count 10
while {$count > 0} {
puts "the value of count is $count"
set count [expr $count-1]
}
for start expression next {
}
#!/usr/bin/expect
for {set count 10} {$count > 0} {incr count -1} {
puts "the value of count is $count"
}
set count [expr $count-1]
#!/usr/bin/expect
proc mycompare {a b} {
if {$a < $b} {
puts "$a is less than $b"
return -1
} elseif {$a > $b} {
puts "$a is greater than $b"
return 1
} else {
puts "$a is equal to $b"
return 0
}
}
set value [mycompare 1 4]
puts "comparison returned $value"
./exp6.exp 1 is less than 4 comparison returned -1
#!/usr/bin/expect
# this program is called exp7.exp
proc connect {} {
expect {
"Name*:" {
send "anonymous\r"
expect {
"Password:" {
send "nobody@nowhere.com\r"
expect "login ok*ftp>"
return 0
}
}
}
}
# timed out
return 1
}
set site [lindex $argv 0]
spawn ftp $site
while {[connect]} {
send "quit\r"
expect eof
spawn ftp $site
}
send "binary\r"
send "cd [lindex $argv 1]\r"
send "get [lindex $argv 2]\r"
send "quit\r"
expect eof
#!/usr/bin/expect log_user 0 spawn pwd expect -re "(^.*/.*)$" set localdir $expect_out(1,string) expect eof log_user 0 spawn ssh moppsy.comp.glam.ac.uk expect "assword: " send "yourpassword\r" expect "\\$" send "cd $localdir" interact
This document was produced using groff-1.19.