Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8720743
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:06:15+00:00 2026-06-13T07:06:15+00:00

This is just a little script to add a user to an e-mail MySQL

  • 0

This is just a little script to add a user to an e-mail MySQL database, assign an alias to him if an argument is defined, send a welcome email to the user and send e-mails to everybody else notifying about the newcomer. But everytime I try to run the script, I only get the message UNEXPECTED END OF FILE. Here’s the script:

#! /bin/bash

USER=$1
SECTOR=$2

if [ -z "${SECTOR}" ];
then
   mysql --host=localhost --user=verysecretdatabaseuser --password=verysecretdatabasepass mydatabase << EOF
   insert into users (email,name,uid,gid,homedir,maildir,crypt,force_change_pwd) values("${USER}@example.com.br","${USER}",1001,1001, "/var/mail/${USER}/","/var/mail/${USER}/.maildir/",ENCRYPT("verysecretdefaultpass"), "yes" );
   EOF
else
   mysql --host=localhost --user=verysecretdatabaseuser --password=verysecretdatabasepass mydatabase << EOF
   insert into users(email,name,uid,gid,homedir,maildir,crypt,force_change_pwd)  values("${USER}@example.com.br","${USER}",1001,1001,"/var/mail/${USER}/","/var/mail/${USER}/.maildir/",ENCRYPT("verysecretdefaultpass"), "yes" ); EOF
   insert into alias(alias,destination) values ("${SECTOR}@example.com.br", "${USER}@example.com.br");
   EOF
fi

# send e-mail so my postfix can create the mail directories 
/usr/sbin/sendmail -f me@example.com.br "${USER}@example.com.br" << EOF
Subject: Bem Vindo!
Seja bem vindo ao Servidor de e-mails da Empresa! Com muito orgulho hospedamos nosso e-mail        em nosso próprio servidor. Em caso de dúvidas contacte <me@example.com.br>
.
EOF

# fetching everyone already in the database
users=`mysql --user=myverysecretuser --password=myverysecretpass -s -N -e "SELECT myverysecretfield FROM    myverysecretdatabase.myverysecretusertable"`

#sending an e-mail to each user
for user in $users
do
   echo "${user}"
   /usr/sbin/sendmail -f me@example.com.br "${user}" << EOF
   Subject: Funcionario novo!
   Prezados, deem as boas vindas ao funcionario novo "${USER}" que acabou de entrar no  departamento de "${SECTOR}". Para se comunicar com o funcionario novo, basta enviar e-mails   para: "${USER}@example.com.br". O funcionario novo tambem recebera e-mails que forem   enviados para "${SECTOR}@example.com.br".
   .
   EOF
done

What am I doing wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:06:16+00:00Added an answer on June 13, 2026 at 7:06 am

    Try this :

    #! /bin/bash
    
    USER=$1
    SECTOR=$2
    
    if [ -z "${SECTOR}" ];
    then
       mysql --host=localhost --user=verysecretdatabaseuser --password=verysecretdatabasepass mydatabase << EOF
       insert into users (email,name,uid,gid,homedir,maildir,crypt,force_change_pwd) values("${USER}@example.com.br","${USER}",1001,1001, "/var/mail/${USER}/","/var/mail/${USER}/.maildir/",ENCRYPT("verysecretdefaultpass"), "yes" );
    EOF
    else
       mysql --host=localhost --user=verysecretdatabaseuser --password=verysecretdatabasepass mydatabase << EOF
       insert into users(email,name,uid,gid,homedir,maildir,crypt,force_change_pwd)  values("${USER}@example.com.br","${USER}",1001,1001,"/var/mail/${USER}/","/var/mail/${USER}/.maildir/",ENCRYPT("verysecretdefaultpass"), "yes" ); EOF
       insert into alias(alias,destination) values ("${SECTOR}@example.com.br", "${USER}@example.com.br");
    EOF
    fi
    
    # send e-mail so my postfix can create the mail directories 
    /usr/sbin/sendmail -f me@example.com.br "${USER}@example.com.br" << EOF
    Subject: Bem Vindo!
    Seja bem vindo ao Servidor de e-mails da Empresa! Com muito orgulho hospedamos nosso e-mail        em nosso próprio servidor. Em caso de dúvidas contacte <me@example.com.br>
    .
    EOF
    
    # fetching everyone already in the database
    users=`mysql --user=myverysecretuser --password=myverysecretpass -s -N -e "SELECT myverysecretfield FROM    myverysecretdatabase.myverysecretusertable"`
    
    #sending an e-mail to each user
    for user in $users
    do
       echo "${user}"
       /usr/sbin/sendmail -f me@example.com.br "${user}" << EOF
       Subject: Funcionario novo!
       Prezados, deem as boas vindas ao funcionario novo "${USER}" que acabou de entrar no  departamento de "${SECTOR}". Para se comunicar com o funcionario novo, basta enviar e-mails   para: "${USER}@example.com.br". O funcionario novo tambem recebera e-mails que forem   enviados para "${SECTOR}@example.com.br".
       .
    EOF
    done
    

    The closing EOF must be at the beginning of the line.

    You can test your script in dry-run mode with :

    bash -n script.sh
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I just wrote this little script. The problem is I want the newest
This sounds funny..just a little experiment. i wanted to simulate a drag drop of
This is just one of those little things I did all the time in
I'm just diving into WPF and find this a little odd and frustrating to
I'm just learning jQuery, and I'm trying to write a little script. To sum
I've this little script which does it's job pretty well but sometimes it tends
Need a little help with this script. It's working but I'd love a way
This just started happening three weeks or so ago. The content of my website
This just saves time. Since I already have a web applciation. I can just
I fear this just may not be possible, but I'm trying to create a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.