0

I want a shell script (ubuntu) which fetchs data from a sql table row by row! And i want to have access on EACH row, e.g. to Check with a simple if statement, u know?

#!/bin/bash
TIME=`date +"%T"`
echo true  > log/ausgefuehrt-$TIME.log
/opt/lampp/lampp start
echo $TIME

#ASSIGNING MYSQL
MYSQL=/opt/lampp/bin/mysql
#$MYSQL -e"select * from ftp.ftp" -u root
$MYSQL -e"select * from ftp.ftp"

#STARTING TO FETCH EACH ROW (trying)
WHILE read ROW ;
        do echo $ROW # HERE <<< is the problem.. i dont know how to access each row :/
done
exit

1 Answer 1

7

Pipe the output of mysql through a while loop as shown below:

$MYSQL -e"select * from ftp.ftp" | while IFS= read -r ROW
do
    echo "$ROW"
done
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.