The at
command has a strange behaviour, and I can't find why.
Story - In 3 days, I'll need to send emails at specific times to make a surprise to someone. I won't be able to monitor if everything is running correctly, because I'll be in a plane for ~20 hours. Everything shall run perfectly. :-)
Script - I am using the at
command to queue jobs for later execution. I created a bunch of files (one per mail), with the following format:
Content of mail1.txt (example)
This is a subject
This is a message...
... on several lines
This is my script:
#!/bin/bash
function sendit {
FROM_MAIL="[email protected]"
RCPT_MAIL="[email protected]"
SUBJECT=$(head -n 1 $1)
MESSAGE=$(tail -n +2 $1)
echo -e "$MESSAGE" |mail -s "$SUBJECT" -r $FROM_MAIL $RCPT_MAIL
}
# Note, time is EDT, it correspond to the date of my server
sendit mail1.txt|at 02:37 May 03
sendit mail2.txt|at 02:38 May 03
sendit mail3.txt|at 03:13 May 03
[...]
I then run my script:
$ bash script.sh
warning: commands will be executed using /bin/sh
job 35 at Tue May 3 02:37:00 2016
warning: commands will be executed using /bin/sh
job 36 at Tue May 3 02:38:00 2016
warning: commands will be executed using /bin/sh
job 37 at Tue May 3 03:13:00 2016
[...]
Everything seems perfect, however, when I check my mails a few minutes after, I saw that some of the mails have been sent... (it seems random)
Any idea?
mail1.txt
so that it has a header block and a body block separated by a blank line, you can usemail
's-t
option to get Subject:, From:, To:, etc from the headers in the message, and you wouldn't have to usehead
ortail
to extract the subject and the body from the file. Seeman mail
and search for-t
.