The shell gets the data from the file and assigns it to the variable

Source: Internet
Author: User

Requirements: Read IP addresses and port numbers from a file, open the IP and ports with Iptables

such as file content:

[email protected] huwei]# cat ip.txt192.168.66.20 22192.168.66.30 10050192.168.66.30 33

The manual action is:

[[email protected] huwei]# iptables-a input-s 192.168.66.20-i eth0-p tcp--dport 22-j ACCEPT

Overwrite the use of script to read the contents of the file, automatically add iptables firewall rules, the script is:

[email protected] huwei]# cat ip.sh#!/bin/shwan0= ' eth0 ' file= '/home/huwei/ip.txt ' while read idoa=$ (echo "$i" |awk-f " {print '} ') b=$ (echo "$i" |awk-f "{print $} ') #此处显示变量的值, you can omit echo" $a "echo" $b "iptables-a input-s $a-i $wan 0-p t CP--dport $b-j accept/etc/init.d/iptables savedone< $FILE

Soil approach, I think there should be a better way to achieve such a function

This article is from the "bottom 20,000" blog, please be sure to keep this source http://huwei555.blog.51cto.com/1347480/1787463

The shell gets the data from the file and assigns it to the variable

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.