You are not logged in.

#1 2011-04-11 17:06:27

jlacroix
Member
Registered: 2009-08-16
Posts: 576

[SOLVED] Getting a Shell Script to Email Me

Hello everyone, I'm playing around with shell scripts trying to get the hang of getting them to email me. I'm playing around with this on my laptop, eventually I am going to try to have my server automate some tasks using cron and email me the status. As an experiment I'm just trying to get something simple like a list of packages emailed to myself. I googled around to come up with this script. I also installed postfix and set up the daemon to run. Here is my test script:

#!/bin/bash
# script to send simple email
pacman -Qe  > /tmp/packages.txt
# email subject
SUBJECT="Test subject"
# Email To ?
EMAIL="my.email.address"
# Email text/message
EMAILMESSAGE="/tmp/packages.txt"
echo "This is an email message test"> $EMAILMESSAGE
echo "This is email text" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
rm /tmp/packages.txt

However, I don't receive an email.

Note: I withheld my email address above so I don't get spam, but it is in the script.

Last edited by jlacroix (2011-04-11 17:43:01)

Offline

#2 2011-04-11 17:25:25

discon
Member
Registered: 2010-06-28
Posts: 23

Re: [SOLVED] Getting a Shell Script to Email Me

I personally use "sendEmail" (http://aur.archlinux.org/packages.php?ID=7335) so I don't have to setup postfix etc. You may want to try with that to determine if it's a problem with your script or with your postfix installation.

Offline

#3 2011-04-11 17:42:37

jlacroix
Member
Registered: 2009-08-16
Posts: 576

Re: [SOLVED] Getting a Shell Script to Email Me

discon wrote:

I personally use "sendEmail" (http://aur.archlinux.org/packages.php?ID=7335) so I don't have to setup postfix etc. You may want to try with that to determine if it's a problem with your script or with your postfix installation.

Thank you for that! I installed it and reviewed the documentation and was successful. If it helps anyone else, here is the code I used (after installing the package) to send myself an email of installed packages, which I can surely use to send myself any report I want:

#!/bin/bash
pacman -Qe > /tmp/packages.txt
sendEmail -f you@yourdomain.com -t smtpusername -u Installed Packages on Computer Name -m These packages are currently installed: -a /tmp/packages.txt -s smtp.server.net:25 -xu smtpusername -xp smtppassword
rm /tmp/packages.txt

Offline

#4 2011-04-11 17:54:40

zyghom
Member
From: Poland/currently Africa
Registered: 2006-05-11
Posts: 432
Website

Re: [SOLVED] Getting a Shell Script to Email Me

ssmtp is another easy way of doing this


Zygfryd Homonto

Offline

#5 2011-04-11 18:17:50

hcjl
Member
From: berlin
Registered: 2007-06-29
Posts: 330

Re: [SOLVED] Getting a Shell Script to Email Me

zyghom wrote:

ssmtp is another easy way of doing this

msmtp as well.

Offline

#6 2011-04-12 07:43:32

Damnshock
Member
From: Barcelona
Registered: 2006-09-13
Posts: 414

Re: [SOLVED] Getting a Shell Script to Email Me

This is not solving your problem, is it?

Don't you wanna know why it didn't work in the first place with the distro included software "mail"?

Try sending an email from the command line and check if you get it...

Regards


My blog: blog.marcdeop.com
Jabber ID: damnshock@jabber.org

Offline

Board footer

Powered by FluxBB