ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Rep:
bash script running by cron
Is there anything wrong with this bash script that would cause it not to work correctly?
Code:
$ crontab -l
# m h dom mon dow command
25 * * * * wget -P/tmp http://www.blackcats-games.net/signup.php; if (grep -q 'current user account limit' /tmp/signup.php ) ; then DISPLAY=:0 xmessage "account registration opened at blackcat" ; fi ; rm -f /tmp/signup.php > /dev/null 2>&1
How could I modify it to only send stderr and stdout to /dev/null if 'current user account limit' does not exist according to grep, so that I would also receive an email?
#!/bin/bash
wget -P/tmp http://www.blackcats-games.net/signup.php > /tmp/logfile 2>&1
if (grep -q 'current user account limit' /tmp/signup.php)
then
DISPLAY=:0 xmessage "account registration opened at blackcat"
cat /tmp/logfile
fi
rm -f /tmp/signup.php /tmp/logfile > /dev/null 2>&1
You can redirect stdout and stderr from any command which is supposed to generate them, to a temporary file. Cat this file only if condition is true and you will receive it by e-mail, otherwise it's lost.
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Original Poster
Rep:
Thank both of you for the information. I followed the advice, and here is what I have now.
Code:
$ crontab -l
# m h dom mon dow command
25 * * * * sh -x "wget -P/tmp http://www.blackcats-games.net/signup.php > /tmp/logfile 2>&1; if (grep -q 'current user account limit' /tmp/signup.php); then DISPLAY=:0 xmessage 'account registration opened at blackcat'; cat /tmp/logfile; fi; rm -f /tmp/signup.php /tmp/logfile > /dev/null 2>&1"
If I use sh -x, won't that send emails every 1 hour? These emails are already getting sent to the wrong person, and he's very pissed. There's something wrong with my mail server configuration that I haven't figured out. I'm going to resolve that problem by using Postfix for smtp instead.
What jlinkels meant is to write a script, test it by sh -x for debugging, then put the script in crontab (instead of the long list of commands to execute). Anyway, sh -x give a trace of all the commands executed from the shell and there is no reason to put it in a cron job. Regarding mail recipient, by default the cron daemon sends mails to the owner of the crontab, but you can always specify the recipient by assigning the MAILTO variable at the beginning of your crontab, e.g.
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Original Poster
Rep:
Emails are being sent to my username. They are being sent to chris@gmail.com. chris is my username, but that is not my gmail account. Here is my sSMTP configuration.
Code:
$ cat /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
#
# The person who gets all mail for userids < 1000
# Make this empty to disable rewriting.
root=christopher.lemire@gmail.com
# The place where the mail goes. The actual machine name is required no
# MX records are consulted. Commonly mailhosts are named mail.domain.com
mailhub=smtp.gmail.com:587
# Where will the mail seem to come from?
rewriteDomain=gmail.com
# The full hostname
hostname=ubuntu
# Are users allowed to set their own From: address?
# YES - Allow the user to specify their own From: address
# NO - Use the system generated From: address
FromLineOverride=YES
UseSTARTTLS=YES # Send SSL/TLS messages to Gmail
AuthUser=mygmailusername # Your Gmail Username
AuthPass=mygmailpass # Your Gmail Password
rewriteDomain=gmail.com # So the message appears to come from Gmail
FromLineOverride=YES # So the message appears to come from Gmail
My deepest apologies if a guide written by me has lead you astray. Can I ask if this you exact ssmtp.conf file? In which case you may need to modify the following values:
Quote:
Originally Posted by fakie_flip
[...]
Code:
$ cat /etc/ssmtp/ssmtp.conf
#
# Config file for sSMTP sendmail
[...]
AuthUser=mygmailusername # Your Gmail Username
AuthPass=mygmailpass # Your Gmail Password
Yes that is my page that you have mentioned, but you will find that it has been extensively modified recently including a move to msmtp. I am usually quite amenable to email discussions of my pages although this forum is fine anyway :-) That particular configuration for ssmtp I have used on my own machine for close on a year without any trouble. The exact instructions were as follows:
Code:
root=Email Address # Your email address
mailhub=smtp.gmail.com:587 # Gmail details
UseSTARTTLS=YES # Send SSL/TLS messages to Gmail
AuthUser=Gmail Username # Your Gmail Username
AuthPass=Gmail Password # Your Gmail Password
rewriteDomain=gmail.com # So the message appears to come from Gmail
FromLineOverride=YES # So the message appears to come from Gmail
hostname=Hostname # Hostname: use hostname -f in a Terminal
and can still be seen in this form on the Ubuntu forums:
My username and password are correct. I just choose not to give that information out to everyone. I am currently configuring Postfix.
My apologies, I had considered that since you left your full email address in sight the rest of the document may have been unmodified :-) It is still my hope that you can get ssmtp running, based on the settings that I provided. The idea of my page containing 'invalid configuration' worries me a great deal. I am normally very meticulous about such things and I would be very keen to correct any errors.
Can any other readers of this forum see the errors here?
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Original Poster
Rep:
I am supposed to choose mbox or Maildir for Postfix. Does anyone know what fetchmail uses? I think mbox. Should my answer be the same as what Fetchmail uses?
I cannot be of much help with SMTP configuration, but regarding the issue about crontab you may consider to use MAILTO= with the complete e-mail address.
Fakie_flip, may he who is without blame cast the first stone... it seems fairly clear that you are the one making the mistake, and are simply not paying enough attention to the document you linked to. it's advice seems perfectly sound but you have clearly dived in far too far without even testing your own config correctly.
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Original Poster
Rep:
Quote:
Originally Posted by acid_kewpie
Fakie_flip, may he who is without blame cast the first stone... it seems fairly clear that you are the one making the mistake, and are simply not paying enough attention to the document you linked to. it's advice seems perfectly sound but you have clearly dived in far too far without even testing your own config correctly.
Quit quoting that religious garbage to me. If I made a mistake in my config, then point it out. Otherwise you're not being of any help.
Distribution: Gentoo Hardened using OpenRC not Systemd
Posts: 1,495
Original Poster
Rep:
Quote:
Originally Posted by colucix
I cannot be of much help with SMTP configuration, but regarding the issue about crontab you may consider to use MAILTO= with the complete e-mail address.
Shouldn't only my gmail username be used with the MAILTO?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.