I am trying to make script that inserts hostname and ip address for certain website in mysql , but before the script inserts results i want to check if they already exist and if it does the script should not insert it.
result_check=$(mysql -uroot -p123qwe webs -e "SELECT COUNT(*) AS NUMBER FROM webs WHERE hostname='$hostname' AND ip='$ip'";)
cat $dir/webs | while read hostname ip; do
if [[ $result_check -eq 0 ]]; then
echo "INSERT INTO webs (hostname,ip) VALUES ('$hostname','$ip');"
fi;
done | mysql -uroot -p123qwe webs;
And this somehow does not work , i can think of other way to get the job done(without if) but i want to make it this way. My webs file looks like that : somedomain.com 192.168.3.3 ... and etc.
This is the error i get:
line 23: [[: NUMBER 0: syntax error in expression (error token is "0")
I have tried many ways to escape this error (changing the brackets from [[ to (( ) but i've had no luck.