当前位置: 技术问答>linux和unix
高分求助redhat shell实现自动telnet和ftp
来源: 互联网 发布时间:2015-08-20
本文导语: 现在情况: a是 redhat 9 b是 防火墙 c是 hpunix 需要在a上执行shell 登陆到防火墙(telnet,防火墙要验证userid/pass)再telnet到c 执行tar 再 ftp到防火墙(同样要验证)->c get刚才的压缩包 外:其他细小功能 每天定...
现在情况:
a是 redhat 9
b是 防火墙
c是 hpunix
需要在a上执行shell
登陆到防火墙(telnet,防火墙要验证userid/pass)再telnet到c 执行tar
再 ftp到防火墙(同样要验证)->c get刚才的压缩包
外:其他细小功能 每天定时启动 压缩包的名字用系统时间命名
我找了很多摸版修改都不成功
a是 redhat 9
b是 防火墙
c是 hpunix
需要在a上执行shell
登陆到防火墙(telnet,防火墙要验证userid/pass)再telnet到c 执行tar
再 ftp到防火墙(同样要验证)->c get刚才的压缩包
外:其他细小功能 每天定时启动 压缩包的名字用系统时间命名
我找了很多摸版修改都不成功
|
set login_prompt 0
expect {
"*login:" {
if [string length $username]!=0 {
send "$usernamer"
exp_continue
} else {
puts [format "%s> absence of username." $EXPSELID]
exit 1
}
}
"*name:" {
if [string length $username]!=0 {
send "$usernamer"
exp_continue
} else {
puts [format "%s> absence of username." $EXPSELID]
exit 1
}
}
"*word:" {
if [string length $pwd1]!=0 {
send "$pwd1r"
} else {
puts [format "%s> absence of password." $EXPSELID]
exit 2
}
}
"*>" {
set login_prompt 1
}
default {
puts [format "%s> Lost sync." $EXPSELID]
exit 4
exit 4
}
}
if $login_prompt==1 {
send "enabler"
} else {
expect {
"*login:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*name:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*word:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*>" { send "enabler" }
default {
puts [format "%s> expect normal privilege prompt." $EXPSELID]
exit 5
}
}
}
这里用的是expect,一个登录路由器并执行enable命令的过程
你的其它动作可以看作一个个的enable命令,只不过期待的输出不同而已
expect {
"*login:" {
if [string length $username]!=0 {
send "$usernamer"
exp_continue
} else {
puts [format "%s> absence of username." $EXPSELID]
exit 1
}
}
"*name:" {
if [string length $username]!=0 {
send "$usernamer"
exp_continue
} else {
puts [format "%s> absence of username." $EXPSELID]
exit 1
}
}
"*word:" {
if [string length $pwd1]!=0 {
send "$pwd1r"
} else {
puts [format "%s> absence of password." $EXPSELID]
exit 2
}
}
"*>" {
set login_prompt 1
}
default {
puts [format "%s> Lost sync." $EXPSELID]
exit 4
exit 4
}
}
if $login_prompt==1 {
send "enabler"
} else {
expect {
"*login:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*name:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*word:" {
puts [format "%s> incorrect username and password." $EXPSELID]
exit 3
}
"*>" { send "enabler" }
default {
puts [format "%s> expect normal privilege prompt." $EXPSELID]
exit 5
}
}
}
这里用的是expect,一个登录路由器并执行enable命令的过程
你的其它动作可以看作一个个的enable命令,只不过期待的输出不同而已
|
ftp -i -n ip