Linux : mail multiple files returned from grep -
i want grep ora- errors in log file.
grep -l ora- *.log suppose returns abc.log , xyz.log
then, want cat content of each file , mail service dynamically (like cat abc.log|mail -s abc.log myemail@email.com)
for above illustration , expecting tow emails contents of abc.log , xyz.log
i have tried doing grep -i -l ora- *.log|xargs cat| mail service myemail@email.com send 1 email.
thanks
if want 1 mail service per file, need loop or run mail kid of xargs:
grep -l ora- *.log | xargs -i mailx -s "{}" -a "{}" myemail@email.com if want attach files single mail, have build command:
cmd="mailx -s logs " f in $(grep -l ora- *.log) ; cmd="$cmd -a '$f'" done eval $cmd myemail@email.com note brittle , breaks when file names contain single ticks.
linux file email grep
No comments:
Post a Comment