Hi,
I need to create a shell script through which i need to populate email addresses in email columns of database table in mysql. Let say if email contains yahoo, hotmail, gtalk than email addresses need to move in their respective columns.
case $yim in
*yahoo*)
mysql <<EOF
INSERT INTO db.table yahoo_email VALUES ('$yim');
EOF
case $msn in
*hotmail*)
mysql<<EOF
INSERT INTO db.table yahoo_email VALUES ('$msn');
EOF
esac;;
What should be the appropriate way to do this kind of job done. Please reply me as soon as possible.
Thanks for the reply. There is minor misktake in script i already sorted out. Now i have some other problem. which i am saving sql query result in variable. Let say
yahoo=$echo('select yahoo from table | mysql db --skip-column-names')
msn=$echo('select msn from table | mysql db --skip-column-names')
which results
yahoo=NULL
msn=NULL
now i want to compare the results that if yahoo and msn is NULL than don't do anything and if yahoo and msn variables contains email addresses than update another table with those values.
my if condition is not working. Please help me out to sort out this issue.
if [[ -n "$yahoo" && -n "$msn" ]]
then
echo "email found. NOT NULL"
else
echo "email are NULL"
fi
It display result "email are NULL"
while it should display "email found. NOT NULL"
because yahoo & msn both variables contains NULL. Please help me how to compare NULL.
Thanks in advance
Why are you writing it in shell script? The MySQL language is quite powerful, you could just do something like "insert into newtable select address from yahoo_email where address not null" or similar (that's pseudo-code, but you can hopefully see what I mean).