User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Shell Scripting section within the Software Development category of DaniWeb, a massive community of 427,222 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,280 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Shell Scripting advertiser: Programming Forums
Views: 1144 | Replies: 5
Reply
Join Date: Jul 2008
Posts: 2
Reputation: subhashmedhi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
subhashmedhi subhashmedhi is offline Offline
Newbie Poster

command to telnet console using shell-script

  #1  
Jul 16th, 2008
hi all,
i have written a shell-script which logs onto a mail-server using telnet and then tries to send the HELO command. The code for the same looks something like this:

exec telnet 150.236.18.66 25;
echo "HELO";

The problem is that though the telnet connection is established the "HELO" command doesn't get executed. Kindly let me know what to do to get the "HELO" command executed.

Thanks in advance.

subhash
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: command to telnet console using shell-script

  #2  
Jul 16th, 2008
telnet 150.236.18.66 25 <<EOF
HELO
whatever else you need to send the mail
EOF

Better yet, have the script write everything it wants to send in a file and do

telnet 150.236.18.66 25 <<filename

Or, even better, simply create a properly formatted mail message and use sendmail to send it.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jul 2008
Posts: 2
Reputation: subhashmedhi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
subhashmedhi subhashmedhi is offline Offline
Newbie Poster

Re: command to telnet console using shell-script

  #3  
Jul 16th, 2008
But if i use the following code

telnet 150.236.18.66 25 <<EOF
HELO
whatever else you need to send the mail
EOF

then the telnet connection is getting closed before the HELO command is executed. Please help me out.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: command to telnet console using shell-script

  #4  
Jul 16th, 2008
Well, it shouldn't be.

Using a "here document" is very standard for this sort of thing.

How do you know it is getting closed before sending that? (It's not something you'll see in the console, or anything.)

Edit: And the second example in my first post should be <filename, not <<filename.
Last edited by masijade : Jul 16th, 2008 at 9:09 am.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Apr 2008
Posts: 39
Reputation: omrsafetyo is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 8
omrsafetyo omrsafetyo is offline Offline
Light Poster

Re: command to telnet console using shell-script

  #5  
Jul 16th, 2008
It actually probably should be in most secure environments...

Try this one:
telnet $mailserver <<END
    user $USER $PWORD
   /path/to/HELO
    exit
END

set up the mailserver, USER and PWORD variables accordingly.
You usually need to authenticate with telnet.
Last edited by omrsafetyo : Jul 16th, 2008 at 12:59 pm.
Reply With Quote  
Join Date: Oct 2007
Posts: 275
Reputation: eggi is on a distinguished road 
Rep Power: 1
Solved Threads: 26
eggi eggi is offline Offline
Posting Whiz in Training

Re: command to telnet console using shell-script

  #6  
Jul 16th, 2008
Hey There,

You can also try

HELO whateveryourdomainis.com
and see if the mailserver isn't just dishing you for not identifying your origin.
or try

EHLO ..etc, etc, etc
and, like omrsafetyo mentioned, you'll probably need to authenticate.

Best wishes,

Mike


Maybe, maybe not.
Originally Posted by subhashmedhi View Post
But if i use the following code

telnet 150.236.18.66 25 <<EOF
HELO
whatever else you need to send the mail
EOF

then the telnet connection is getting closed before the HELO command is executed. Please help me out.
Linux and Unix Tips, Tricks and Individual Advice - The Linux and Unix Menagerie!
------------------------------------------------------------------------
Having trouble passing cert exams? Check out How To Pass Any Computer Certification Test!
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Shell Scripting Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the Shell Scripting Forum

All times are GMT -4. The time now is 11:27 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC