-
E-mail script
I'm attempting to use telenet to send SMTP data.
I know the protocol and can send the mail manually via telnet.
However, I cannot find a way to use a script to feed telnet.
I'm using the MS telnet client built into WinXP.
The end goal is to automate this process into a scheduled batch file.
So far the command stream looks like this - All the information is static except for the message.
Help!
-
I'm not sure if that's possible with the built-in XP telnet client. Why can't you just cron it on the remote server? Or - does the dynamic message have to come from the windows machine?
Without knowing much about your situation here, I would think the better way to approach it would be to have the remote *nix server cron a job to 'pull' the dynamic data from the windows server (or have the windows server 'push' it, either way), and then send off whatever e-mails it needs.
From my experience, batch files are extreemly limiting in terms of functionality, but a cron'd bash script can rule the world :p
You could of course, compile some sort of simple Java, or C++ program to do this remote telnet / mail procedure for you, and then have a scheduled NT batch file exec it. But that's usually wwaaaaay more effort than should be necessary, for something that could be written in 5 lines of a bash script.
In short - it sounds to me like you need to re-think your approach, and/or the business problem you're trying to solve. When you start doing things like using BATCH files to navigate through a remote telnet session, you're usually not seeing the forest for the trees.
-
I'm no longer a coder. My coding skills went the way of Burroughs, Algol and Cobol. That's why I'm thinking script.
I don't have a *nix box available to me until I get my wife a new machine and retire her PII-266 box. Then I must relearn the stuff I tried hard to forget 20 years ago - System V rel 2.
The data is coming from an EFS file system on a W2k3 server.
My next approach might be to use a Perl script from within IIS but I'm not sure how to get access to the variable data from IIS. My IIS 6.0 server is not configured to send mail at the moment.
I just started on this problem today, so I'm sure there is a long learning curve ahead.
-
Problem solved with a few lines of Perl and an afternoon of reading and trial & error testing.
This code will read an entire file into memory then e-mail it to a list of recipients. It can be placed in a batch file for periodic execution by Windows Scheduler (tested) or a webpage that refreshes periodically (not tested).
Code:
use strict;
use Net::SMTP;
my $from = 'whoever';
my @recip_list = ('[email protected]', '[email protected]');
my $smtp_host = "x.x.x.x";
my @loglines = ();
my $VERSION = "1.0";
my $smtp = Net::SMTP->new($smtp_host, Timeout => 30) || die "Can't connect to $smtp_host.\n";
open INPUT, "c:/crypto/cryptolog" || die "Open cryptolog failed.\n";
@loglines = <INPUT>;
$smtp->mail($from) || die "cannot mail from.\n\n";
$smtp->recipient(@recip_list);
$smtp->data();
$smtp->datasend("To:\[email protected]\n");
$smtp->datasend("Subject:\tLog\n\n");
$smtp->datasend( "@loglines\n\n");
$smtp->dataend;
$smtp->quit;
-
Hey nice work, I'm glad you worked it out ua549. Perl is a perfect fit for these kinds of things, especially if you don't have the joys of bash scripting available.