LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 02-06-2007, 04:06 AM   #1
rk4k
LQ Newbie
 
Registered: Feb 2007
Posts: 9

Rep: Reputation: 0
SMTP/MX Check Expect Script


All

I want to telnet bunch of mx servers from expect script just to check the mailserver program used from their banner (if exist) from the expect script like this :
Quote:
#!/usr/bin/expect -d

mxcount=`wc -l mxfile`
count=1
mxs=$( awk 'NR == '$count'' mxfile )
var=$(expect -c"
set timeout 5
spawn telnet $mxs 25 ---> the problems lies here and the rest
set timeout 10
expect "220*"
set timeout 10
send "helo just-test.org\n"
set timeout 10
expect "250*"
send "quit\n"
exit
")
while [ "$count" -le $mxcount ]
do
echo "$var"
let "count += 1"
done
mxfile contain the mailservers hostname I want to check separated by line.
And the script not work. I'm newbie pretended to be expert :-)

Please help.

Thanks.

Last edited by rk4k; 02-06-2007 at 04:09 AM.
 
Old 02-06-2007, 04:49 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
you're using bash like conventions in an expect script, which i'd assume have not been mimicked by tcl here. what i do is make an expect script to do ONE job, and wrap it in bash, sometimes just a one liner...

for i in $(echo mysmtplist); do ./myexpect.exp $i; done

and let that sort the looping out for you.
 
Old 02-06-2007, 09:36 PM   #3
rk4k
LQ Newbie
 
Registered: Feb 2007
Posts: 9

Original Poster
Rep: Reputation: 0
Thanks for the pointer

I modified the script , read the expect man page , and this the new code

Code:
#!/usr/bin/expect --

set hostname "[lindex $argv 0]"
set timeout 5
spawn telnet $hostname 25
set timeout 10
expect "220*"
set timeout 10
send "helo just-test.org\n"
set timeout 10
expect "250*"
send "quit\n"
exit
Works as Expected !!!

TIA
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect Script coolest Programming 7 02-16-2009 03:59 PM
Script... variables with expect? Manana Linux - Networking 1 01-19-2007 04:41 AM
How to combine Expect and Shell script Uday123 Programming 0 12-27-2005 09:01 AM
trying to execute an expect script in .bashrc smaudlin Red Hat 2 01-02-2005 01:34 AM
BAD SU- from a cronned expect script ganninu Linux - General 1 07-18-2004 10:49 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:01 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration