List:General Discussion« Previous MessageNext Message »
From:Ralf Narozny Date:September 6 2002 4:30pm
Subject:Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for
example
View as plain text  
Hello!

walt wrote:

>"Keith Burke [Experience IT]" wrote:
>
>  
>
>>Greetings,
>>
>>        I'm new to this list but not to MySQL. I've been using MySQL on
>>Linux with PHP for the past year or two. I've always managed to sort out
>>any problems by looking at the documentation on the website but my
>>current problem has me perplexed.
>>
>>        I need to be able to send Emails to people from MySQL command
>>line.
>>
>>        I'm importing a text file of users via a cronjob. MySQL process
>>the data and segragates it into different tables. My problem is that I
>>want MySQL to Email the plain text passwords to the users before it
>>MD5's them. I cannot find any references that MySQL can run external
>>programs [sendmail].
>>    
>>

You do it with a cronjob, so why not using some of the nice Unix 
commands on the file before importing it. I use bash or awk for such 
things...maybe like this

(Assuming your file (the_file) looks like this: <USERNAME> <PASSWORD> ...

Write an awk script, like this (mailsend)

#########################
#!/bin/awk -f

{
    message( $1, $2 )
}

function message( uid, pwd ) {
    print "Dear " uid "!" >"/tmp/mail.txt";
    print "" >"/tmp/mail.txt";
    print "Your username is:" uid >"/tmp/mail.txt";
    print "Your password is:" pwd >"/tmp/mail.txt";
    print "" >"/tmp/mail.txt";
    print "Be aware that your password will be saved in an encrypted 
format, so noone can read it!" >"/tmp/mail.txt";
    close( "/tmp/mail.txt");

    cmd = "cat /tmp/mail.txt | mail -s 'Your password for xyz' " uid 
"@somewhere.com";
    system(cmd);

}

#########################

chmod mailsend 700

mailsend the_file

(BTW: in the above example might be syntax error, because I did not test 
it ;-) )

Greetings
 Ralf

-- 
Ralf Narozny

Besuchen Sie uns auf der DMS-Expo. SAP, Dokumenten-
management oder das komplette Office ins Portal einbinden?
Wir zeigen es Ihnen - vom 3. bis 5.9. auf der Messe Essen
Halle 3, Stand 3255

SPLENDID Internet GmbH & Co KG
Skandinaviendamm 212, 24109 Kiel, Germany
fon: +49 431 660 97 0, fax: +49 431 660 97 20
mailto:rnarozny@stripped, http://www.splendid.de



Thread
[MySQL] HELP: Can MySQL run external programs... Sendmail for exampleKeith Burke [Experience IT]6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for examplewalt6 Sep
    • RE: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleKeith Burke [Experience IT]6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleGerald Clark6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleGelu Gogancea6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail forexampleMichael T. Babcock6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail forexampleRalf Narozny6 Sep
Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleGelu Gogancea6 Sep
RE: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleKeith Burke [Experience IT]6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleGelu Gogancea6 Sep
    • RE: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleKeith Burke [Experience IT]6 Sep
      • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleGelu Gogancea6 Sep
  • Re: [MySQL] HELP: Can MySQL run external programs... Sendmail for exampleEd Carp6 Sep