awk can do the grep bit
Code:
#!/bin/bash
EMAILALERT="email@gmail.com"
HOSTNAME="$(hostname)"
MYSQLDATADIR=$(mysqladmin var | awk '/datadir/{ print $4}')
MYDs=( "$(find ${MYSQLDATADIR} -type f -not -path "${MYSQLDATADIR}mysql/*" -name "*.MYD")" )
# put path/filenames in array
email_body () {
# this just prints things
printf "%s\n" "Server has MyISAM tables in database"
printf "%s\n" "${MYDs[@]}"
}
if [[ ${#MYDs[@]} -gt 0 ]]
then
email_body #removeme | mail -s "$HOSTNAME has MyISAM tables in database" $EMAILALERT
else
echo "nothing in the array"
fi
once you are happy with the email_body output remove the #removeme to go live with the pipe to mail
Edit, the array is probably overkill
you might get away with setting -E on mail
from man mail
-E Don't send messages with an empty body.
Code:
#!/bin/bash
EMAILALERT="email@gmail.com"
HOSTNAME="$(hostname)"
MYSQLDATADIR=$(mysqladmin var | awk '/datadir/{ print $4}')
find ${MYSQLDATADIR} \
-type f \
-not -path "${MYSQLDATADIR}mysql/*" \
-name "*.MYD" \
| mail -E -s "$HOSTNAME has MyISAM tables in database" $EMAILALERT
but I'm not 100% certain of what you actually want