2012-02-03 45 views
0

我有兩個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?

+1

如何'[[$(iptables的-L STAT 2>的/ dev/null的| WC -1)-lt 1]] && echo「STAT鏈未找到。退出」&& exit「? – 2012-02-03 12:58:38

回答

0

iptables-save輸出可能更容易grep這項任務。

0

檢查鏈STATUS被加載,如果是退出:

/sbin/iptables-save | grep -q '\-A STATUS ' && exit 0 
相關問題