mercredi 25 avril 2018

using for in loop with sql output

I have a roles.txt file that contains

admin
user

SELECT ROLE_NAME FROM SENTRY_ROLE WHERE ROLE_NAME produces:

admin

Im trying to echo all the roles from roles.txt that are not in the sql_output (user in this example). This is what i have so far:

for filename in roles.txt
do
sql_output=$(mysql -N -e "SELECT ROLE_NAME FROM SENTRY_ROLE WHERE ROLE_NAME = '$filename';") 


if [ -z "$sql_output" ]
then
  echo "sql_output is empty" #this is where i want to echo all the roles that are not in the output of sql_output AKA "user"
else
  echo "\$sql_output is in sql_output"
  fi
done

Aucun commentaire:

Enregistrer un commentaire