LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 05-06-2009, 11:14 AM   #1
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 322

Rep: Reputation: 30
Script to telnet?


I want to write a script (bash?) to telnet and login to a POP3 mail server and do a STAT. If something wrong happens (timeout, etc) I want it to write the output to a file.

Is this straightforward to do? Is bash not the best way to do this?
 
Old 05-06-2009, 11:31 AM   #2
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Maybe Python is better for this kind of task. The package poplib allows connections to a POP3 server and let you run any command defined in the POP3 protocol (RFC 1725) including STAT.
 
Old 05-06-2009, 11:36 AM   #3
Zeno McDohl
Member
 
Registered: Apr 2005
Location: Saratoga, NY
Distribution: Slackware
Posts: 322

Original Poster
Rep: Reputation: 30
Well I want as little as possible involved here to ensure any connection issues that arise are on the POP3 server end, which is why I wanted to use telnet in a script somehow.

I'll look into Python though.
[EDIT] It was easy to get this done:
Code:
import getpass, poplib

M = poplib.POP3('mail.server.com')
M.user('email')
M.pass_('blah')
numMessages = len(M.list()[1])
print numMessages
Now I just need to figure out how to write the output to a file if something wrong happens.

Last edited by Zeno McDohl; 05-06-2009 at 12:08 PM.
 
  


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
telnet script peji Linux - Newbie 2 10-27-2007 06:52 AM
Running Telnet in a script, want to save Telnet output, howtodothis??? anil3 Linux - Software 2 03-08-2006 04:01 PM
telnet script help GUIPenguin Linux - General 2 01-16-2005 02:48 PM
telnet script tn1681 Linux - General 3 07-25-2002 10:09 PM
telnet script tn1681 Programming 2 07-24-2002 08:47 PM

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

All times are GMT -5. The time now is 03:34 AM.

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