#! /usr/bin/expect
set command [lindex $argv 0]
set passwd [lindex $argv 1]
spawn su - root -c $command
expect "password:|口令:"
send $passwd\r
expect eof
exit
#! /usr/bin/expect
set passwd [ lindex $argv 0 ]
set shell_path [ lindex $argv 1 ]
spawn su - root
expect "口令:|Password:"
send $passwd\r
expect {
"su*" {
#expect eof
#exit 24
#send "echo password error\r"
expect eof
exit 10
}
"*#*" {
#send "echo login succ\r"
#expect eof
#exit 11
send "echo \r"
send "$shell_path\r"
}
}
expect eof
#exit
例子:
#! /usr/bin/expect
set uoa_passwd [ lindex $argv 0 ]
set uoa_ip [ lindex $argv 1 ]
set uoa_path [ lindex $argv 2 ]
spawn scp ../bme_productconfig.xml uoa@$uoa_ip:$uoa_path/uoarun/data/templates
expect "?*"
send $uoa_passwd\r
expect eof