到rpmfind可以下载到expect
#----------------------------------------------
例一:追加到文本前(利用vi)
#!/usr/bin/expect
set a [lindex $argv 0]
set b [lindex $argv 1]
spawn vi $b
expect "*"
send "O"
send "$a"
send "3"
send ":"
send "wq"
send "\r"
expect eof
[lindex $argv 0] 第一个变量,类似""
[lindex $argv 1] 第二个变量,类似""
#----------------------------------------------
例二:自动su
#!/usr/bin/expect
set password 123
spawn su
expect "*password:"
send "$password\r "
interact
#----------------------------------------------
例三:passwd tmp用户
#!/usr/bin/expect
spawn passwd tmp
set password 345
expect "*password:"
send "$password\r"
expect "*password:"
send "$password\r"
expect eof
阅读(1577) | 评论(0) | 转发(0) |