用于防火墙的bash脚本占位符 [英] Placeholders in bash script for firewall
问题描述
我想编写函数,这将使得:
-
从循环中的文件中读取文本
$ b - 执行命令
reading text from file in a loop
executing command
我有一个命令
用于`grep -v ^#/etc/rc.d/b bad_input.ip`中的BAD_INPUT_IP;做
iptables -I INPUT -s $ BAD_INPUT_IP -j DROP
完成
我想重新建立这个函数:
pre $函数go_loop(){
为`grep -v ^#中的BAD_INPUT_IP $ 1`;做
iptables -I INPUT -s $ BAD_INPUT_IP -j DROP
完成
}
go_loop/etc/rc.d/bad_input.ip
我做的任务的第一部分。一切都好。但是如何做这个命令的占位符?
$ b $ iptable -I INPUT -s $ BAD_INPUT_IP -j DROP
我会有很多不同的命令,我将需要一个循环。你可以帮我吗 ?感谢。
在运行函数之前设置变量
<$对于`grep -v ^#$ file`中的BAD_INPUT_IP,函数go_loop(){
; pre> 做
iptables -I INPUT -s $ BAD_INPUT_IP -j DROP
完成
}
file =/ etc / rc.d / bad_input.ip
go_loop
i want to write function, that will make:
I have a command
for BAD_INPUT_IP in `grep -v ^# /etc/rc.d/bad_input.ip`; do
iptables -I INPUT -s $BAD_INPUT_IP -j DROP
done
I want to rebuild this to function:
function go_loop (){
for BAD_INPUT_IP in `grep -v ^# $1`; do
iptables -I INPUT -s $BAD_INPUT_IP -j DROP
done
}
go_loop "/etc/rc.d/bad_input.ip"
First part of task i made. Everything is ok. But how to make placeholder for this command ?
iptables -I INPUT -s $BAD_INPUT_IP -j DROP
I will have a lot of different commands, where i will need a loop. Can you help me ? Thanks.
Set the variable before running going to the function
function go_loop (){
for BAD_INPUT_IP in `grep -v ^# $file`; do
iptables -I INPUT -s $BAD_INPUT_IP -j DROP
done
}
file="/etc/rc.d/bad_input.ip"
go_loop
这篇关于用于防火墙的bash脚本占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!