This is my script so far, i cant get it running as it is either giving me a syntax error near unexpected token '}' on line 44, or is giving me an unexpected end of file. I cant see what im doing wrong, if theres anything that looks wrong, please let me know.
Thanks.
#!/bin/bash
### List of functions
LOGFILE="/var/log/secure"
OUTPUTFILE="/home/ssh/log.txt"
BLOCKLIST="/home/ssh/blocklist.txt"
MAX_ATTEMPTS="5"
ACCEPTED_IPS= "172.16.0.1 172.16.0.2"
menu()
{
echo "1) Press 1 to run the script."
echo "2) Press 2 to view the logfile."
echo "3) Press 3 to view the output file."
echo "4) Press 4 to view the blocklist."
echo "5) Press 5 to exit."
echo -n "Please make a valid selection: "
read menu
case "$menu" in
1) runscript ;;
2) runlog ;;
3) lookout ;;
4)viewblock ;;
5) exitscript ;;
*) echo "\$menu\" is not a valid option." ;;
esac
}
runscript()
{
while true; do
### counts failures and makes a two column output file in the format of <count> <ipaddr>
grep -E "sshd.+Failed" $LOGFILE |
grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' |
sort | uniq -c > $OUTPUTFILE
### directs output of $output file to 'read' in the next loop
exec < $OUTPUTFILE
### check to see if the IP address is already in the blocklist
while read count IPADDR; do
PRE=$(grep $IPADDR $BLOCKLIST)
### if it isnt in the list...
if [ -z "$PRE" ]; then
### and it occurs greater than or equal to $MAX_ATTEMPTS...
if ["$COUNT" -ge "$MAX_ATTEMPTS" ]; then
###we place it into the blocklist...
echo $IPADDR >> $BLOCKLIST
### and make a log entry.
logger "$IPADDR ($COUNT failures) added to the blocklist"
fi
fi
done
}
runlog()
{
cat $LOGFILE ###displays contents of /home/log/secure
}
lookout()
{
cat $OUTPUTFILE ### displays contents of /home/ssh/log.txt
}
viewblock()
{
cat $BLOCKLIST ### displays contents of /home/ssh/blocklist.txt
}
exitscript()
{
echo "Be sure to run this script again in the near future."
}
exit