使用expect命令在shell中远程执行脚本指令
发布时间
阅读量:
阅读量
The system includes a tool that can realize automatic interactive functionality. The interaction process is implemented through the use of expect-send.
注意:
脚本文件的运行方式不同于bash shell, 其中expect example.sh
当向一个脚本传递参数时,bash shell会通过1, 2等变量来接收这些参数;而expect则会将这些脚本执行时的参数存储在数组argv中,并在脚本处理过程中将其设置到指定变量名中(例如:set 变量名 [lindex argv 参数])。
#!/usr/bin/expect
set ip [lindex $argv 0]
set password [lindex $argv 1]
set timeout 2
spawn telnet $ip
expect "*femto login:"
send "root\r"
expect "*Password:"
send "$password\r"
# 进入指定的机器后,就可执行相应的命令或者脚本
全部评论 (0)
还没有任何评论哟~
