LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 846|回复: 5

如何做一个scrpit让文件读入某文件参数

[复制链接]
发表于 2006-3-29 11:01:51 | 显示全部楼层 |阅读模式
dhcpd.conf是个conf文件
我要通过脚本创建他的hardwareadd 和ip add对应 并输入到dhcpd.conf里面去
简单的说就是
我要让脚本去读一个ipadd 和hardwareadd的对应文件 并在创建dhcpd.conf的时候把这个对应文件内的参数倒入进dhcpd.conf里面去 以dhcpd的格式

现在我就做到
对应文件
aaa
hard=00:xx:xx:xx:xx:xx
ip=192.168.0.1

然后在脚本里面定义
hard=`cat /aaa | grep "hard" | cut -d = -f 2`
ip=`cat /aaa | grep "ip" | cut -d = -f 2`

host clienta {
                   hardware $hard;
                   ipadd   $ip;
}

只能做到这样 ...但是要是地址一多实事我怎么判断 取其他的hard地址和ip对应关系
怎么做个循环
有5个对应关系 那么就做client1-5  然后就不再继续做添加 host client 这样...
有思路 但是不知道怎么写 orz
请前辈们帮帮忙.....:beat :beat :beat
发表于 2006-3-29 11:24:32 | 显示全部楼层
我实在看不懂楼主的表述?
你是想从dhcpd.conf文件中读取信息作为命令的参数吗?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-29 11:36:30 | 显示全部楼层
不是
我要用脚本做dhcpd.conf  脚本里面固定语句可以echo 比如goble setting
但是ip 和hardware 地址 我要脚本去读某个文件比如叫aaa
aaa里面就是ip=多少 mac=多少

这样 我只要修改aaa文件 就可以重新生成新的dhcpd.conf
就是这意思= =
回复 支持 反对

使用道具 举报

发表于 2006-3-29 14:35:30 | 显示全部楼层
Post by cxfcxf
不是
我要用脚本做dhcpd.conf  脚本里面固定语句可以echo 比如goble setting
但是ip 和hardware 地址 我要脚本去读某个文件比如叫aaa
aaa里面就是ip=多少 mac=多少

这样 我只要修改aaa文件 就可以重新生成新的dhcpd.conf
就是这意思= =

My thoughts:
1. If aaa has a decent format, then it should be easy to grab the hw and ip info into an array with odd index one kind and even another kind.
2. Loop the array and format the output, then assign to a variable.
3. sed the conf file and insert the variable to wherever you wanted.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-3-30 14:04:57 | 显示全部楼层
思路我有....就像我前面说的...但是循环和调用格式不知道怎么写...
资料片面呀....有没有整合在一起的例子??? 或者相关的..
回复 支持 反对

使用道具 举报

发表于 2006-3-31 00:06:39 | 显示全部楼层
With array, the easilest is to use for loop, such as
  1. for((i=0;i<${array[@]};i++)); do statments; done
复制代码
In statments, you can format the array output and then assign to a variable. Now you can sed your conf file and find a insert point to insert the variable in.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表