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-blcheck
date" 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
blcheck
so 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:52blcheck
is abash
script. So, for best results, you should call it asbash blcheck ....
, notsh blcheck ...
because, on many systems,sh
is notbash
. – John1024 Nov 03 '15 at 07:06bsd-mailx
orheirloom-mailx
? – cas Nov 03 '15 at 08:31#!/bin/bash
as the first line and make it executable withchmod +x blcheck
. then you can run it with justblcheck
if it's in the PATH or./blcheck
if it's in current dir. – cas Nov 03 '15 at 08:32blcheck
as 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^M
character 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\r
probably only appears in the output ifverbose
is 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 file2
and 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 latest
date" email@address
– Snowie Nov 04 '15 at 08:59