编写shell脚本遇到的命令执行出错问题
执行下面命令能封禁单个IP:
iptables -I INPUT -s *.*.*.* -j DROP
截止到当前,对兵团的短信接口的CC攻击已达至少981个,封禁这些IP,肯定要搞个脚本,但我写的脚本却在执行时报错:
'ptables v1.4.7: Invalid target name `DROP Try `iptables -h' or 'iptables --help' for more information.
当我在脚本头部嵌入#!/bin/bash发现报错:
-bash: ./dark-test.sh: /bin/bash^M: bad interpreter: No such file or directory
多了^M符号,这说明就是Linux下的文本dos格式和Unix格式的问题,dos格式和unix格式差别就在于换行符。
所以用VIM打开脚本,使用命令:set fileformat=unix,保存后再执行,问题成功解决!