Bash script blcheck from github format issues with emailing output
Console output displays correct, but when sent to email via mailx will on go as attachment, not to body.
33%% dnsbl.inps.de ✓
50%% xbl.spamhaus.org ✓
Output to file or email example:
16%% dnsbl-3.uceprotect.net ^MESC(BESC[m 16%% dnsbl-.uceprotect.net ✓ESC(BESC[m
Advise pls on how can I correct the format in file & email ?
CMD that's not sending to eamil body:
sh blcheck -v xx.xx.xx.xx | mail -s "server-blcheckdate" user@email.exampel
script: https://github.com/IntellexApps/blcheck
After assistance of @john1024 & @cas & previous post Removing Control Chars below cmd resolved issue.
CMD: ./blcheck-l -v xx.xx.xx.xx | perl -pe 's/\e([^[]]|[.*?[a-zA-Z]|].*?\a)//g' | col -b | mail -s "blcheck-l -v `date`" email@address
darko-poljak has submitted a pull request on github with a new option to make output friendly for non interactive use.
https://github.com/IntellexApps/blcheck/pull/2
blcheckso that it uses colors if stdout is a terminal, and not use colors if stdout is a pipe. e.g.if [ -t 1 ] ; then RED=$(tput setaf 1) ; GREEN=... ; else RED= ; GREEN= ; ... ; fi– cas Nov 03 '15 at 06:52blcheckis abashscript. So, for best results, you should call it asbash blcheck ...., notsh blcheck ...because, on many systems,shis notbash. – John1024 Nov 03 '15 at 07:06bsd-mailxorheirloom-mailx? – cas Nov 03 '15 at 08:31#!/bin/bashas the first line and make it executable withchmod +x blcheck. then you can run it with justblcheckif it's in the PATH or./blcheckif it's in current dir. – cas Nov 03 '15 at 08:32blcheckas per your link. After I removed the calls totput(as per this answer), I have tried running it and I do not find any escapes (\E) or alerts (\a) in the output. I tested this by running your perl script on the output, and then comparing withcmp: no difference. Can you tell under what circumstances the modified script produces these characters? Or, if not, can show me sample output that contains those characters so I can look in the source to try to see where they are coming from? – John1024 Nov 04 '15 at 03:58^Mcharacter appears in the script several times in the form\r. You can remove it by doing a search-and-replace in your favorite editor or by running sed 's/\r/CR/g' blcheck >blcheck.new. However,^M` is not one of the characters affected by your perl script and it seems like an unlikely character to trigger a problem with text attachment. Try removing it and see what happens but there is a chance that the problem is somewhere else. – John1024 Nov 04 '15 at 06:08\rprobably only appears in the output ifverboseis set. It might be simpler to just try it without-v. – John1024 Nov 04 '15 at 06:31file1. Then runperl -pe 's/\e([^[]]|[.*?[a-zA-Z]|].*?\a)//g' file1 | col -b >file2. Then rundiff file1 file2and let's see where the differences really are. – John1024 Nov 04 '15 at 07:18./blcheck-latest -v xx.xx.xx.xx | perl -pe 's/\e([^\[\]]|\[.*?[a-zA-Z]|\].*?\a)//g' | col -b | mail -s "blcheck latestdate" email@address– Snowie Nov 04 '15 at 08:59