我正在使用tinydns,需要动态地更改数据文件中的一些ip。我想为它使用bash脚本。
例如,数据文件:
+sub1.example.org:282.196.222.245:14400
+sub2.example.org:278.179.280.253:14400
+sub3.example.org:285.117.214.234:14400bash脚本有两个变量:
old="282.196.222.245"
new="127.0.0.1"我期望这样的结果:
+sub1.example.org:127.0.0.1:14400
+sub2.example.org:278.179.280.253:14400
+sub3.example.org:285.117.214.234:14400将旧ip替换为new (使用awk、sed或smth否则)的最佳方法是什么?
发布于 2014-09-02 22:35:56
我认为避免对data进行猴子补丁是比较干净的;相反,要从几个文件中生成data,其中一个文件只包含动态记录(S)。
然后,在bash中,您可以只使用echo "+sub3.example.org:285.117.214.234:14400" >data.dynamic; make或类似的。
示例Makefile:
data.cdb : data
tinydns-data
data : data.static data.dynamic
cat data.static data.dynamic >datahttps://serverfault.com/questions/570413
复制相似问题