How to call function having telnet session within a shell script

Closed
Report
Posts
1
Registration date
Wednesday July 15, 2015
Status
Member
Last seen
July 15, 2015
-
Hi I am trying to do as shown below. I have created a shell function to login. How do i call the login() inside a shell script???

test.sh

#!/usr/bin/expect -f
login () {
#!/usr/bin/expect -f
set timeout 30
set name [lindex $argv 0]
set user [lindex $argv 1]
set password [lindex $argv 2]
spawn telnet $name
expect "login:"
send "$user\r"
expect "Password:"
send "$password\r"
expect "\$ "
send "exit\r"
expect eof

}

expect login 10.1.1.1 dev dev > log_fm.txt

thanks in advance