Mailx - Daily email of log file to list of recipients - solaris

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.

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

inserting system date into subject field of ssmtp 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

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

Sending email with CC BCC and sender's address in unix mailx

I want to send email from HP unix using mailx command.
I have to include cc and bcc in my email and have to use the specific email address as the sender.
But -r (which is to define the sender's email address) will disalbe ~ commands so if i have to define the sender's email address, i cannot use ~c and ~b commands for cc and bcc.
Is there any work around???? cos these are the requirements from the user.
Thanks.
Just re-order the arguments to mailx command. That would give the desired result
$ echo "something" | mailx -s "subject" -b bcc_user#some.com -c cc_user#some.com -r sender#some.com recipient#example.com
In my case I have to keep multiple id's in cc which has been done by giving the email-id's comma separated one by one as below:
$ echo -e "Hi Team, \n \n Action Needed \n \n Regards, \n XYZ team"| mailx -s "subject" -b bcc_user1#some.com,bcc_user2#some.com -c cc_user1#some.com,cc_user2#some.com -r sender#some.com receiver#xyz.com
Also made use of the echo command to pass multiple lines to mailx utility. Thought it will be helpful.

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