inserting system date into subject field of ssmtp email - email

I'd like to know the syntax for inserting the current date/time into the subject line of an email sent by ssmtp.
I've got a cronjob emailing the tail of my syslog whenever the system reboots.
Here is the the cronjob:
#reboot tail -1000 /var/log/syslog | mail -s "the system rebooted, here's the syslog" address#gmail.com &> /dev/null
Is there a simple way of inserting the system date into the subject line field? I haven't found a way to add it.

You should be able to make it print the current date and time by inserting $(date) into your subject line string.
Try:
#reboot tail -1000 /var/log/syslog | mail -s "$(date): the system
rebooted, here's the syslog" address#gmail.com &> /dev/null

Related

echo text and tail log to pipe to email

I want to echo text as well as tail the last part of a log to pipe it to email. I can easily do one or the other, but how do I do both without first writing everything to a file and then emailing that? I basically want to combine the below two commands into one to only send out one email.
echo "There is an error in the log, see the below for detail" | mail -s "error in the log" xxx#yyy.zzz
and
tail -n 10 /var/log/error.log | mail -s "error in the log" xxx#yyy.zzz
Thanks.
You could use the concatenate command along with process substitution:
cat <(echo "There is an error in the log, see the below for detail") <(tail -n 10 /var/log/error.log) | mail -s "error in the log" xxx#yyy.zzz

Problems with using uuencode on RHEL to send mail attachment

I have a unique situation where I'm going from an AIX platform to RHEL for a vendor supported application. Within the application, I can send a command (limited to the amount of characters I can send) that will email me results of a print job.
To do this in AIX, I'm passing the following command:
uuencode temp.txt | mail -s "test" email#address.com
This sends standard output to the email as an attachment named temp.txt. Temp.txt doesn't exist on the AIX server.
I have downloaded the rpm for uuencode for Linux, but it doesn't work in the same fashion. It sends an email with what looks like garbage (could be missing MIME header).
I'm looking for a similar command. To simulate outside of the application, I use the following in AIX:
echo "testing mail" | uuencode temp.txt | mail -s "test" email#address.com
I know mailx -a <filename> would work if I had a filename, unfortunately I'm working with standard output vs a file.
Any help will be appreciated.

Mailx - Daily email of log file to list of recipients

I was given a few example usages of mailx and asked to come up with another by my manager.
I have a program that will be left running. Once a day, we want to send the log file it generates to a list of recipients.
This was the closest example I received
00 11 * * * unset noclobber;cat /home/emailList.txt /tools/temp/summary.csv | mailx -t -s "Report `/bin/date`" -r person#company.com > /home/file.log
Seems like I want something like:
MyProgram | mailx -t -s "Report `/bin/date`" /home/emailList.txt -r person#company.com
But here, I'm not sending it once a day. This sends at MyProgram closing, right? I'm also sending MyProgram's output, not it's log file.
Thanks in advance.

procmail not piping e-mail content to a file

I have a postfix server and procmail installed and working.
The problem is when I try to output the content of an e-mail to a file.
I have the following script:
/var/log/user1/fooscript.sh
#!/bin/bash
echo "Trying to get e-mail" > success.txt
echo $1 >> success.txt
/var/log/user1/.procmailrc
VERBOSE=off
PMDIR=$HOME/.procmail
LOGFILE=$PMDIR/procmail.log
INCLUDERC=$PMDIR/rc.filters
/var/log/user1/.procmail/rc.filters
:0
* ^From:(.*\<)?(test#gmail\.com)\>
| /var/log/user1/fooscript.sh
After sending an e-mail, /var/log/user1/.procmail/rc.filters
contains:
From test#gmail.com Thu Jul 18 05:08:13 2013
Folder: /var/log/user1/fooscript.sh 513
but the success file only shows:
Trying to get e-mail
(empty line)
I've chmod 777 all files and directories, so don't think its a permissions issue.
Any help would be greatly appreciated.
Your script gets the message via standard input (STDIN). Try:
#!/bin/bash
echo "Trying to get e-mail" > success.txt
# append data read from STDIN to success.txt file
cat >> success.txt
BTW for more complicated scripts use custom lock to avoid running two scripts in parallel:
:0 w :fooscript.lock
* ^From:(.*\<)?(test#gmail\.com)\>
| /var/log/user1/fooscript.sh

cron: sending output to file then EMAILing file to me

I am writing a series of cron jobs. I want each task to log its output to file, and then I want the contents of the file mailed to me at say me#somewhere.com
I think logging the output to file can be done using simple pipe redirection like this:
30 0 * * * /path/to/script1 > task1.log
30 1 * * * /path/to/script2 > task2.log
However, I am not sure how to mail the files (or simply their contents) to me in seperate emails to me#somewhere.com
Also, is there a way to dynamically create the log file names, based on the date, so that the log names would be something like %Y%m%d.task1.log ?
Where the prefix is the date ?
I am running on Ubuntu 10.0.4 LTS
If your system has a working /usr/bin/sendmail (doesn't have to be sendmail sendmail, most mail servers provide a /usr/bin/sendmail wrapper script) then you can use the mail(1) utility to send mail:
echo "hello world" | mail -s hello me#example.com
mail(1) is pretty primitive; there's no MIME file attachments, you're stuck with plaintext.
If mutt(1) is installed, you can use MIME to attach files:
echo "hello world" | mutt -a task*.log -- me#example.com
As for giving the logfiles dates:
$ echo "hi" > $(date "+%Y%m%dlog.txt")
$ cat 20110328log.txt
hi
$
So, try this:
30 1 * * * /path/to/script2 > $(date "+\%Y\%m\%dlog.txt") && mutt -a $(date "+\%Y\%m\%dlog.txt") -- me#example.com