쉘스트립트의 for 문을 이용하여 iptables 적용을 하려합니다.
AAA는 IP 정보가 담긴 파일이고 여기에 iptables 적용을 위한 옵션을 포함시켜놨구요.
script.sh iptables 룰 적용을 위한 스크립트파일.
debug.txt 는 왜 적용이안되는지 알아보기위해 디버그파일입니다. (script.sh 에서 생성하게 했어요)
----------------------------------------------------------
debian:/home# cat AAA
-s 1.1.1.1
-s 2.2.2.2
-s 3.3.3.3
-s 100.100.100.1
-s 100.100.100.0/24
-m mac --mac-source AA:AA:AA:AA:AA:AA
-m iprange --src-range 100.100.100.1-100.100.100.5
----------------------------------------------------------
debian:/home# cat script.sh
#!/bin/sh
for AAA in `cat AAA`
do
echo -e $AAA >> debug.txt
/sbin/iptables -A FORWARD $AAA -j ACCEPT
done
----------------------------------------------------------
debian:/home# cat debug.txt
-s
1.1.1.1
-s
2.2.2.2
-s
3.3.3.3
-s
100.100.100.1
-s
100.100.100.0/24
-m
mac
--mac-source
AA:AA:AA:AA:AA:AA
-m
iprange
--src-range
100.100.100.1-100.100.100.5
----------------------------------------------------------
위에서 debug.txt 결과처럼
AAA 파일 내용에서 띄어쓰기 마다 줄이 바뀌는것 같습니다 ㅡㅡ;
어떻게 해결방법이 없을까요?
for 문을
for 문을 쓰는것보다는, 방법을 달리하여, 파일을 줄단위로 처리하는게 좋지 않을까요?
답글 달고나니, 아래 비슷한 답글이 달렸네요!
그런데,, read 를 저렇게 쓸수도 있다는걸 처음 알았네요! 후후...
음..
for AAA in `cat AAA` 에서..
AAA 라는 변수에는 cat AAA 결과중에서 white space 로 구분된 토큰이 들어갑니다.
아래처럼 그냥 while 문으로 바꾸시면 될 것 같네요.
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
되면 한다! / feel no sorrow, feel no pain, feel no hurt, there's nothing gained.. only love will then remain.. 『 Mizz 』
댓글 달기