Last active
August 9, 2024 04:24
-
-
Save realyukii/01f147331f7a438907606d4ac908ced7 to your computer and use it in GitHub Desktop.
check if list of users exists on SQL table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# note | |
# you can use grep to count occurrences of each character in a string | |
# check total of non-exists and exists user with: grep -c '0' output_file.txt | |
email_file="emails.txt" # File containing emails, assuming delimeted by CRLF | |
database="evaluasi" | |
# Loop through each email in the file | |
tr -d '\r' < "$email_file" | while IFS= read -r email; do | |
# Query to check if the email exists in the users table | |
query="SELECT COUNT(*) FROM users WHERE email = '$email';" | |
# Execute the query using mysql client | |
result=$(mysql --defaults-extra-file=config.cnf "$database" -se "$query") | |
echo "$email -> $result" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
example content of config.cnf: