设为首页
收藏本站
用户名
Email
自动登录
找回密码
密码
登录
注册
快捷导航
平台
Portal
论坛
BBS
文库
项目
群组
Group
我的博客
Space
搜索
搜索
热搜:
shell
linux
mysql
本版
用户
LinuxSir.cn,穿越时空的Linuxsir!
»
论坛
›
Linux 综合讨论区 —— LinuxSir.cn
›
shell进阶应用、shell编程
›
expect的问题
返回列表
查看:
1002
|
回复:
2
expect的问题
[复制链接]
fucj
fucj
当前离线
积分
24
IP卡
狗仔卡
发表于 2008-4-7 09:22:37
|
显示全部楼层
|
阅读模式
以下是我用的expect的脚本
#!/usr/bin/expect
set user [lindex $argv0]
set ipadd [lindex $argv 1]
spawn -necho ssh $usr@@ipadd
expect "Enter*"
send "password\r"
expect eof
exit
我再执行./expect.sh x x
请问为什么我用这个脚本ssh登陆成功后,再输入任何命令都没有返回信息。
回复
使用道具
举报
提升卡
置顶卡
沉默卡
喧嚣卡
变色卡
显身卡
yui
yui
当前离线
积分
4
IP卡
狗仔卡
发表于 2008-4-14 11:51:50
|
显示全部楼层
expect不是这样用的,我给你一段FTP的脚本,差不多的,楼主可以参考
######## Start FTP ########
set FTPPROMPT "ftp>"
spawn ftp $HOST
set FTP_SPAWNID $spawn_id
if {$FTP_SPAWNID == 0} {
ftp_client_err "FTP spawn error"
return 99
}
######## Start login ########
expect {
-re "230 User \[a-zA-Z ]+logged in.*$FTPPROMPT" {
ftp_client_info "$USER login successful"
}
-re "ame \\($HOST:\[a-zA-Z]+\\):" {
send "$USER\r"
expect {
-re "assword:" {
send "$PASSWD\r"
expect {
-re "230 \[a-zA-Z ]+logged in.*$FTPPROMPT" {
ftp_client_info "$USER login successful"
}
-re "230 Login successful. Have fun.\r\n" {
ftp_client_info "$USER login successful!!!"
}
-re "Remote system type is Windows_NT.\r\n" {
ftp_client_info "Remote system type is Windows_NT."
}
timeout {
ftp_client_err "FTP --- login timeout"
return 99
}
}
}
timeout {
ftp_client_err "FTP password timeout"
return 99
}
}
}
timeout {
ftp_client_err "FTP username timeout"
return 99
}
}
######## Change to source directory ########
send "cd $SRCDIR\r"
expect {
-re "250 CWD command successful.*$FTPPROMPT" {
ftp_client_info "250 Directory successfully changed."
}
-re "200 Directory changed.*$FTPPROMPT" {
ftp_client_info "200 Directory successfully changed."
}
-re "250 Directory successfully changed." {
ftp_client_info "250 Directory successfully changed."
}
timeout {
ftp_client_err "FTP cd command timeout"
return 99
}
}
send "bin\r"
expect {
-re "200 Type set to I.*$FTPPROMPT" {
ftp_client_info "200 Switching to Binary mode"
}
-re "200 Switching to Binary mode.*$FTPPROMPT" {
ftp_client_info "200 Switching to Binary mode"
}
timeout {
ftp_client_err "FTP bin command timeout"
}
}
send "prompt\r"
expect {
-re "$FTPPROMPT" {
}
timeout {
ftp_client_err "FTP prompt command timeout"
}
}
send "mget infile.*\r"
expect {
-re "226 Transfer complete.*$FTPPROMPT" {
ftp_client_info "226 Transfer complete"
}
timeout {
ftp_client_err "FTP get command timeout"
}
}
set spawn_id $FTP_SPAWNID
send "QUIT\r"
catch {close -i $FTP_SPAWNID}
catch {wait -nowait -i $FTP_SPAWNID}
}
回复
支持
反对
使用道具
举报
显身卡
yvqq
yvqq
当前离线
积分
82
IP卡
狗仔卡
发表于 2008-4-14 20:06:37
|
显示全部楼层
#!/usr/bin/expect
set user [lindex $argv0]
set ipadd [lindex $argv 1]
spawn -necho ssh $usr@$ipadd
expect {
"*assword*" {
send "password\r"
}
expect {
"*@*" {
send "ls -l \r"
send "exit \r"
}
}
expect {eof}
回复
支持
反对
使用道具
举报
显身卡
返回列表
高级模式
B
Color
Image
Link
Quote
Code
Smilies
您需要登录后才可以回帖
登录
|
注册
本版积分规则
发表回复
回帖后跳转到最后一页
浏览过的版块
MySQL
BSD 讨论专题
Archlinux讨论区
Redhat/Fedora/CentOS Linux
硬件设备 Linux 驱动
Java 程序设计开发讨论
Debian Linux
Linux发行版 Turbolinux专题
Slackware Linux
Copyright © 2002-2023
LinuxSir.cn
(http://www.linuxsir.cn/) 版权所有 All Rights Reserved.
Powered by
RedflagLinux!
技术支持:
中科红旗
|
京ICP备19024520号
快速回复
返回顶部
返回列表