Hello folks,
I have number of ip listed in a text file and would telnet them on port 25 and exit if 220 banner if found.
I'm able to successfully run the script and get the output on tty, but I intend to capture the telnet session output in a file which i'm unable to do so either with script command or redirection.
Code:
#!/bin/bash
for ip in `cat ip.txt`
do
expect<<EOF
spawn telnet
expect "telnet>"
send "open $ip 25\n"
expect "^220"
send "quit\r"
EOF
done
and this outputs as below
Code:
# sh conn.sh
spawn telnet
telnet> open 74.125.79.27 25
Trying 74.125.79.27...
Connected to ey-in-f27.1e100.net (74.125.79.27).
Escape character is '^]'.
220 mx.google.com ESMTP z1si4136250eem.165
spawn telnet
telnet> open 74.125.113.27 25
Trying 74.125.113.27...
Connected to vw-in-f27.1e100.net (74.125.113.27).
Escape character is '^]'.
220 mx.google.com ESMTP hn4si4261830vdb.140
This output is on the screen, which i'm unable to send it to any file.
Please assist me in with this problem.