I have 2 digital clean servers - one is a few years old, one is new.
On the old server, any cron jobs that run with an echo, the echoed content is emailed to me. I'm pretty sure this happened by default - I didn't configure this myself.
On the new server, echoed content is not emailed. I have tried to send an email using the following, which worked fine, so my understanding is that email is running ok.
echo "This is the body of the email" | mail -s "This is the subject line" "me#myemail.com"
Can anyone tell me if there's a specific option for this, or if I'm missing something?
All crons email any output on stdout or stderr to the user owning the crontab.
If you don't see that mail you
look in the wrong mailbox
have something odd in $HOME/.forward
have a glitch in your crontab (odd MAILTO perhaps)
have a command that doesn't produce any output
Related
I'm running a user LaunchAgent in El Cap that is supposed to call postfix to send me an email when a certain automatically generated file is 0 length, meaning that something went wrong. Here's the line from the bash script where $me is my username:
echo 'Darn it' | mail -s 'Export failed' "$me"
It works fine if I run the script manually, but mail won't send anything when the agent runs.
By dumb luck I found that if I follow this command with the following command, the message will get sent:
/usr/local/bin/terminal-notifier -message "File export failed." -title "Alert"
Other following commands won't do it (like echo, for example).
Any idea what's going on there?
I am using CronTab to schedule sending e-mails hourly with the latest logged errors in a logged file debug.log
So far I managed to set CronTab to send an e-mail with the last 5 logged errors (using a shell script). The thing is that I don't want the same errors to be sent: If an error has been sent at 12 pm , I don't want it to be sent again at 1 pm if it is among those 5.
Note: I used 5 as a random number. It was to test to see if I can do this. But I need help with what I previously mentioned.
I don't need to know how to send the e-mail and all that. All I need is to know how to output the errors logged in the file in the last hour.
You can try using command below
tail -f debug.log | grep 'ERROR_INDICATOR' >> error.log
and then modify your crontab job script to delete the content of the error.log right after you send the email.
Alright, so I have been asked to help with this script. Basically what it needs to do is email a user if there is an error associated with an ID. Now I won't go into too much detail on that because the sql portion does that correctly. What I don't know how to do is pull out each user email from the sql individually and email them one at a time then attach the error ticket associated with it to the email body.
My KSH script as I have it now.
#!/usr/bin/ksh
# sets all environment variables
. /data/pmes/pmes/pmes_scripts/pmes_Env_Var.config
# sets the results of the .sql file to the emailBody Variable
emailBody=`sqlplus -s $USERID/$PPASSWD#$DATABASE #/data/pmes/pmes/pmes_scripts/testingmail2.sql`
# these email addresess are emailed when the script completes
MAIL_ID='emailme#yoursite.com'
(echo "$emailBody")|mailx -s "Test Email`" $MAIL_ID
Output of echo $emailBody
aaron.heckel#yoursite.com 20140801_BR_Bob,D_PZXKGX steve.naman#yoursite.com 20140816_AM_Andrew,D_PZXKGX
(It is basically email then the issue ID. Each item has a space in between them)
Any help would be appreciated. I'm very new with mailing and sqlplus in UNIX.
There appear to be a number of answers to this question, but none of them seem to work:
I would like to send email from my localhost to a gmail account. The following command does nothing as far as I can tell:
mail -s "Hello!" address#gmail.com
After Ctrl-Ding to finish editing, there is no failure notification or anything, and the message never appears in that gmail account's inbox (or spam folder). I've tried various different ways of using that command from around the internet, but it appears that it just silently fails to send to nonlocal addresses. Any ideas?
I am using Debian Wheezy
EDIT: To be clear, the issue is not that I get command line prompts, which I know I can avoid with pipes etc. The issue is that mail is simply never sent. The command returns after a while, and it just silently fails.
Thanks!
You can use an echo with a pipe to avoid prompts or confirmation.
echo "This is the body" | mail -s "This is the subject" address#gmail.com
Make sure postfix or the MTA of your choice is installed and running.
sudo /etc/init.d/postfix status
I've done my research and tried lots of way but to no avail, i still could not get my postfix mail to run the script.
content of /etc/aliases
test2: "|/home/testscript.sh"
content of /home/testscript.sh Note: i've tried many kind of ways in the script. even a simple echo does not work.
#!/bin/sh
read msg
echo $MSG
i've tried running the script and it works fine.
So would you tell that it's working?
Even if you successfully direct mail to the script, you're not going to see the output of the "echo" command. If you expect to get an email response from the script, the script will need to call out to /bin/mail (or sendmail or contact an SMTP server or something) to generate the message. If you're just looking to verify that it's working, you need to create some output where you can see it -- for example, by writing the message to the filesystem:
#!/bin/sh
cat > /tmp/msg
You should also look in your mail logs (often but not necessarily /var/log/mail) to see if there are any errors (or indications of success!).