Pleas help me to setup this crontab
I have three file
iptables.sh Code:
IPT=/sbin/iptables Code:
/etc/init.d/iptables start I chmod all file and folder to 777. When i run command to test sh /root/iptables/autoblock.sh, it says Quote:
And i unable to save crontab. Code:
crontab -e Code:
*/2 * * * * /root/iptables/autoblock.sh Please help me. Thank you |
Hmmm...
The ':wq' should work as long as your $EDITOR is vi/vim. I'd start by adding a proper sh-bang to the top of those scripts (so you don't need to prefix with the 'sh'): Code:
#!/bin/bash Code:
*/2 * * * * /root/iptables/autoblock.sh > /dev/null 2>&1 See if that helps. |
There is some issue with your script. It is giving you errors. In your first script I do not see ipblock variable declared.
Also if your default editor is vi then you should use Esc + :wq to save and quit. Esc to go from insert mode to command mode. Oh yes, and if you forgot, insert the shebang line at the top of the script. rizhun has given that already. |
Thank you, i have create crontab sucessful. Anyone please correct my code ? I still get error
: command not found 2: : command not found 4: ./iptables.sh: line 7: LIST: command not found ./iptables.sh: line 8: ^$: command not found |
Do you have the shebang line at the top of the script? Forget about the ipblock comment in my previous post I missed it.
|
Yes i added it, and still got error
|
Try
Code:
netstat -atun | grep SYN_RECV | awk '{print $5}' | cut -d: -f1 |sort | uniq -d | sort -n > blocked.ips Quote:
|
Still got message, repo
Code:
Code:
#!/bin/bash //remove LIST in line #4 and still got error Code:
./iptables.sh: line 5: ^$: command not found |
Code:
egrep -v -E “^#|^$” egrep -v -E ^#|^$ |
Try changing:
SPAMDROPMSG=”SPAM LIST DROP” to: SPAMDROPMSG='SPAM LIST DROP' |
I replaced, but still got same error :(
Code:
[root@server ~]# sh /root/iptables/autoblock.sh |
So you want to block the ip's you got from
Quote:
Quote:
Quote:
|
Thank you repo, it work now. Can you please help me a question.
About above script, how to make old-block-ip won't be replaced ? I mean if my current blocked.ips have two ip 1.1.1.1 and 1.2.2.2 And another ip must be block is 1.3.3.3 will be add in block.ips. Then, blocked.ips will have 3 ips. My current script don't do that, it remove two old ips and replace by new ip. Sorry my bad english. |
Quote:
Quote:
|
All times are GMT -5. The time now is 05:21 PM. |