I have a script that scans an IP address for an open FTP port and then inputs that IP address into a MySQL database. However, upon running the script, I receive the following message:
"ERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '192.168.1.104 INSERT INTO users (ip) VALUES (192.168.1.104)' at line 1"
I have set up the database and named it 'nmapscans' with a table named 'users' and field name 'ip' that is of the data type 'int(20)'
Here is my incomplete script:
#!/bin/bash
ipadd=`ifconfig wlan0 | awk '/inet / {print $2}' | cut -d: -f2`
nmap -sV $ipadd -p 21 -oG ftp1 ; cat ftp1 | grep closed > ftp2
cut -d: -f2 ftp2 | cut -d"(" -f1 > ftp3
#cat ftp3
function checkDatabase {
RESULT=`mysql -u root -pQwerty17 --skip-column-names -e "SHOW DATABASES LIKE 'nmapscans'"`
if [ "$RESULT" == "nmapscans" ]; then
echo "Database exists"
else
echo "Database does not exist"
fi
}
checkDatabase && echo $?
echo "INSERT INTO users (ip) VALUES ("100");" | mysql -uroot -pQwerty17 nmapscans;
function input_data {
#if [[ checkDatabase ]]
inputfile="ftp3"
cat $inputfile | while read ip; do
echo "$ip"
echo "INSERT INTO users (ip) VALUES ("$ip");"
done | mysql -uroot -pQwerty17 nmapscans;
#fi
}
input_data && echo $?
if [[ input_data == 0 ]]
then
echo "it worked" && rm ftp1 ftp2 ftp3
else
echo "it failed"
fi
exit
Mysqldoesn't know what to do with that. Just remove theecho "$ip"line.