Fetch column values one by one from mysql using shell -


i have table named student in mysql database. table has column named email.

i use following command send email specific student, identified pid:

$email=$(mysql --login-path=local --database=ccps -ss -e "select email student pid=132054");    echo "this sample mail" | mail -s "test" $email 

i want know how send email each , every student in database. don't know how use loop on column email.

thank you.

the direct way can think of is:

for email in `mysql --login-path=local --database=ccps -ss -e "select email student order pid;"`         echo "this sample mail" | mail -s "test" $email done 

if haven't come across them before, quotes before mysql , @ end of command left-handed ones, not usual single quotes. earlier comment says, php better/easier @ constructing more sophisticated emails.


Comments