set timeout 10
set IP [lindex $argv 0]
set LOGIN [lindex $argv 1]
set PASSWORD [lindex $argv 2]
set METHOD [lindex $argv 3]

if {[string match "TELNET" $METHOD]} {
    spawn telnet $IP
    expect ">>User name:*"
    send "$LOGIN\r"
} elseif {[string match "SSH" $METHOD]} {
    spawn ssh $LOGIN@$IP
    expect {
	"(yes/no)?*" {
		send "yes\r"
		}
    }
}

expect ">>User password:*"
send "$PASSWORD\r"
expect {
    "*>" {
        send "enable\r"
    }
    "#" {
        send "\r"
    }
}
expect "*#"
send "save configuration\r"
expect "*#"
send "exit\r"