标题: 【已解决】20元求助,linux下更新文本文件的部分内容。 [打印本页]
作者: sysclock 时间: 2019-5-22 10:32 标题: 【已解决】20元求助,linux下更新文本文件的部分内容。
本帖最后由 sysclock 于 2019-5-22 11:48 编辑
版上牛人真多,继续发帖子活跃气氛:
=================================================
1、要更新的文件名sysconfig.ini,内容如下
#[Version]
VERSION=1.0
#[NetConf]
dac_name=beijing
dac_numb=15
dac_mac=00:0a:35:00:1e:xx
dac_ip=192.168.0.2xx
netmask=255.255.255.0
#[TrigerConf]
trigerSquThd=600
trigerSquRatio=30
Ch1TrigerThd=600
Ch1TrigerRatio=30
Ch1TrigerLen=1000
Ch2TrigerThd=600
Ch2TrigerRatio=30
Ch2TrigerLen=1000
Ch3TrigerThd=600
Ch3TrigerRatio=30
Ch3TrigerLen=1000
Ch4TrigerThd=600
Ch4TrigerRatio=30
Ch4TrigerLen=1000
#[TransConf]
ServerIP=192.168.0.102
FtpPort=21
Username=test
Password=test
DestionFolder=S1
IsDeleted=1
SavePath=/tmp/
#[StationConf]
StationId=15
StationDesc=CP
2、另外一个文件名字remote.ini,内容和格式和他一样。通过ftp已经下载到本地了。
3、如果检测到remote.ini的版本号比sysconfig.ini更大,那么用老的文件sysconfig.ini中的以下两项目更新新的remote.ini文件
dac_name
dac_numb
4、举例,
(1)假如remote.ini内容如下:
#[Version]
VERSION=1.01
#[NetConf]
dac_name=xx
dac_numb=00
dac_mac=00:0a:35:00:1e:xx
dac_ip=192.168.0.2xx
netmask=255.255.255.0
#[TrigerConf]
trigerSquThd=600
trigerSquRatio=30
Ch1TrigerThd=600
Ch1TrigerRatio=30
Ch1TrigerLen=1000
Ch2TrigerThd=600
Ch2TrigerRatio=30
Ch2TrigerLen=1000
Ch3TrigerThd=600
Ch3TrigerRatio=30
Ch3TrigerLen=1000
Ch4TrigerThd=600
Ch4TrigerRatio=30
Ch4TrigerLen=1000
#[TransConf]
ServerIP=192.168.0.102
FtpPort=21
Username=test
Password=test
DestionFolder=S1
IsDeleted=1
SavePath=/tmp/
#[StationConf]
StationId=15
StationDesc=CP
(2)经过脚本更新后,remote.ini的内容应该如下:
#[Version]
VERSION=1.01
#[NetConf]
dac_name=beijing
dac_numb=15
dac_mac=00:0a:35:00:1e:xx
dac_ip=192.168.0.2xx
netmask=255.255.255.0
#[TrigerConf]
trigerSquThd=600
trigerSquRatio=30
Ch1TrigerThd=600
Ch1TrigerRatio=30
Ch1TrigerLen=1000
Ch2TrigerThd=600
Ch2TrigerRatio=30
Ch2TrigerLen=1000
Ch3TrigerThd=600
Ch3TrigerRatio=30
Ch3TrigerLen=1000
Ch4TrigerThd=600
Ch4TrigerRatio=30
Ch4TrigerLen=1000
#[TransConf]
ServerIP=192.168.0.102
FtpPort=21
Username=test
Password=test
DestionFolder=S1
IsDeleted=1
SavePath=/tmp/
#[StationConf]
StationId=15
StationDesc=CP
================================
谢谢
作者: Batcher 时间: 2019-5-22 11:33
- #!/bin/bash
- dnameSys=$(awk -F '=' '/dac_name=/{print $2}' sysconfig.ini)
- dnumbSys=$(awk -F '=' '/dac_numb=/{print $2}' sysconfig.ini)
- dnumbRem=$(awk -F '=' '/dac_numb=/{print $2}' remote.ini)
- if [[ $dnumbSys -gt $dnumbRem ]]; then
- sed "s/dac_name=.*/dac_name=$dnameSys/; s/dac_numb=.*/dac_numb=$dnumbSys/" remote.ini > remote.ini.new
- mv remote.ini.new remote.ini
- fi
复制代码
作者: amwfjhh 时间: 2019-5-22 11:45
- #!/bin/bash
-
- nVerLocal=`sed -n "/VERSION/{s/.*=//;p}" sysconfig.ini`
- nVerRemote=`sed -n "/VERSION/{s/.*=//;p}" remote.ini`
- echo Local Version : $nVerLocal
- echo Remote Version : $nVerRemote
- nDiff=`awk -v x="${nVerLocal}" -v y="${nVerRemote}" 'BEGIN{printf "%d\n",(y-x)*100}'`
- if [ $nDiff -gt 0 ]
- then
- echo Remote version is newer than local version.
- echo Now will update the dac_name and dac_numb
- dac_name=`sed -n "/dac_name/{s/.*=//;p}" sysconfig.ini`
- dac_numb=`sed -n "/dac_numb/{s/.*=//;p}" sysconfig.ini`
- echo dac_name : ${dac_name}
- echo dac_numb : ${dac_numb}
- sed "s/dac_name.*/dac_name=${dac_name}/;s/dac_numb.*/dac_numb=${dac_numb}/;" remote.ini >remote_new.ini
- echo Output file : remote_new.ini
- echo Newest content is :
- cat remote_new.ini
- fi
复制代码
欢迎光临 批处理之家 (http://bathome.net./) |
Powered by Discuz! 7.2 |