expect简单示例

2014-11-22 0 696
expect简单示例
#!/usr/bin/expect
##################################################################################
#FileName:      test_ssh.exp
#Author:        Defias
#Description:
#Version:       1.0
#Date   2017-7-22
#example:./test_ssh.exp ip  user  passwd
##################################################################################
set timeout 30

set remote_ip [lindex $argv 0]

set user [lindex $argv 1]

#set passwd "Npaswd!@#\$11"
set  passwd [lindex $argv 2]

if {$argc != 3} {
    send_user "num of arg is error!\n"
    exit
}

spawn ssh -l $user $remote_ip

expect "*password:*"

send "$passwd\n"

expect "]#"

send "touch a.txt\r"

send "ifconfig\r"

#send "exit\r"
expect "]#"
#interact

遇见资源网 shell expect简单示例 http://www.ox520.com/16743.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务