# emailing log files as body text



## hm2k (Jan 19, 2011)

In an attempt to make the eggdrop logs searchable, I wrote a script (backuplogs.sh) which would send a copy of the logs by email so they could be searched from there.

I tried two methods, both of which had issues:

`(uuencode $filename $filename) | mail -s $subject $mailto`
`mail -s "$subject" $mailto < "$file"`

The issue are as follows:

Email clients are unable to search contents of attachments
The log file will not render as body text as the mail command attempts to parse the file for headers.

Possible solutions:

Encode the body (not as an attachment)
Escape the body so the text will not be rendered by the mail command

Unfortunately I've not worked out how to do this.

Any ideas?


----------



## SirDice (Jan 19, 2011)

If it's plain text don't uuencode it. You can just add it.


```
% cat some_text | mailx -s 'my subject' me@example.com
```


----------



## hm2k (Jan 19, 2011)

Awesome, I didn't expect that to work for some reason, but it did.

Cheers.


----------



## Pushrod (Jan 19, 2011)

So how does one send a file as an attachment?


----------



## SirDice (Jan 19, 2011)

Pushrod said:
			
		

> So how does one send a file as an attachment?



Just uuencoding it should normally work. If you want a 'real' MIME attachment you'll have to use something like mail/mutt:
[cmd=]mutt -a somefile.jpg -s 'my subject' me@example.com < body.txt[/cmd]


----------



## DutchDaemon (Jan 19, 2011)

mail/biabam is also nice (depends on bash, alas, but a nice simple prog nonetheless).


----------



## Alt (Jan 21, 2011)

hm2k if your logs are managed by syslogd, you can pipe it to mail(1) from syslogd.conf when they rotating for example


----------



## hm2k (Jan 22, 2011)

they aren't, they are eggdrop logs, however I'm sure somebody will find that tip useful.


----------

