LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   postfix setup to work with email script. (https://www.linuxquestions.org/questions/linux-general-1/postfix-setup-to-work-with-email-script-4175478801/)

Mark382717 09-27-2013 05:32 PM

postfix setup to work with email script.
 
123

onebuck 10-05-2013 08:08 AM

Moderator Response
 
Please do not edit content to remove the original content unless the changes correct the thread. Here at LQ we try to help everyone. New threads that are issues that may/will help you and other members are valuable to us at LQ. Please be patient for LQ members to respond thus hopefully helping you and other LQ members.

Original Post content with vbcode tags added for clarity;
Quote:

I have cobbled together a small script that emails my username when an SSH connection is made by one of the people who I have given access too (Script listed below). The script works great, but I'd like to have it email a non local email address rather than just the local user.

I did some reading and according to the articles I found made the following changes. The email just still just sits in mailq. Any help getting this working would be greatly appreciated. Thanks in advance.

1) Added these lines to
/etc/postfix/main.cf
--------------
Code:

relayhost = smtpserver.com:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes

--------------
*smtpserver.com is a the smtp server for the hosting company where I have my domain hosted.

2) Added this line to
/etc/postfix/sasl_passwd
--------------
smtpserver.com:587 myemail@address.com : password
--------------


3) I then ran
--------------
postmap /etc/postfix/sasl_passwd
--------------

4) Then:
--------------
cat /etc/ssl/certs/Thawte_Premium_Server_CA.pem | tee -a /etc/postfix/cacert.pem
--------------


5) Finally, I restarted postfix:
--------------
/etc/init.d/postfix reload
--------------



The email script is as follows and resides in
/etc/ssh/sshrc;
--------------
Code:

#!/bin/bash
# send email when any ssh login is successful
## set IP variable
ip=`echo $SSH_CONNECTION | cut -d " " -f 1`

# email subject
SUBJECT="SSH login just occurred."

# Email To ?
EMAIL="user@host"

# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "  -- Alert -- "> $EMAILMESSAGE
echo "SSH Login was successful">> $EMAILMESSAGE
echo "User $USER just logged in from $ip">> $EMAILMESSAGE
echo `date`>> $EMAILMESSAGE
echo "  -- End alert --" >>$EMAILMESSAGE
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
# clear contents of tmp file
echo "Blank File"> $EMAILMESSAGE

--------------
Thread now reopened!


All times are GMT -5. The time now is 07:33 AM.