I have the following bash script to read logs and check for brute force then block violating IP using iptables.
#!/bin/bash
#blah blah run some commands to get the IP
iptables -A INPUT -s $p -j REJECT --reject-with icmp-host-prohibited
echo "BANNED $p FOR $COUNT ATTEMPTS" |wall
I did chmod 755. When I run the command from terminal it works fine. But when I setup a cronjob using crontab -e as root, it gets the IP and echos the "BANNED ..." message to the wall but nothing is added to the iptables list.
PS. I tried both #!/bin/bash and #!/bin/sh but no luck.
iptables.which iptableswill give it to you foriptables, do the same for the others.