检查用户链是否在bash脚本中可用
问题描述:
我有两个bash脚本。在第一个用户链会像检查用户链是否在bash脚本中可用
#!/bin/bash
iptables -X STATS
iptables -N STATS
iptables -I INPUT -j STATS
被创建在另一个bash脚本我将插入规则类似
#!/bin/bash
# HERE: If STATS-Chain not available end skript
iptables -A STATS --dport 80
我怎么能在该位置HERE:
检查STATS链可? 是否有可能与iptables本身或仅与iptables -L
一些 sed/awk/grep ... magic?
答
iptables-save输出可能更容易grep这项任务。
答
检查链STATUS被加载,如果是退出:
/sbin/iptables-save | grep -q '\-A STATUS ' && exit 0
如何'[[$(iptables的-L STAT 2>的/ dev/null的| WC -1)-lt 1]] && echo“STAT链未找到。退出”&& exit“? – 2012-02-03 12:58:38