標籤:style c class blog code tar
1.從一串字串中擷取特定的資訊
要求1:擷取本機IP:menu.lst為系統鏡象的IP設定檔,需要從中擷取到本機IP資訊(從檔案擷取資訊)
1 timeout 12 default 03 4 title live5 find --set-root /casper/vmlinuz6 kernel /casper/vmlinuz boot=casper ignore_uuid showmounts ip=eth0,10.0.66.66,255.255.240.0,10.0.64.37 initrd /casper/initrd.lz
menu.lst
要求2:修改(替換)原檔案中特定內容:CenterServer.conf為SCC可執行程式的設定檔,需要將設定檔中的domain值改為本機IP。
1 #CenterServer config file 2 3 # Logging Type: syslog|cerr|cout|file 4 LoggingType = cout 5 6 # Logging level: NONE|CRIT|ERR|WARNING|INFO|DEBUG|STACK 7 LogLevel = DEBUG 8 #LogLevel = INFO 9 10 #sip listen port11 UDPPort = 506012 #SCC domain ip13 Domain = 10.0.73.1414 CallTimeout = 6015 16 #RDS client working thread num (1--8)17 RDSClientThreadNum = 218 #RDS Client Log on|off19 RDSClientLog = off20 21 #Daemon process yes|no, default=yes22 IsDaemon = no23 24 #Web server addr25 WebServerUrl = http://localhost:900026 27 #SCC state Database28 DataBase = scc29 MySqlUserName = root30 MySqlUserPasswd [email protected]66631 32 MsIp = 127.0.0.133 MsPort = 9999
CenterServer.conf
實現指令碼:
1 #!/bin/sh 2 MENULST="/JONET_boot/menu.lst" 3 SCC_PATH="/JONET/bin/SCC/CenterServer.config" 4 LOCALIP="`awk -F ‘,‘ ‘{print $2}‘ $MENULST |grep .`"; 5 echo $LOCALIP 6 7 modify_scc() 8 { 9 DOMAIN="`cat $SCC_PATH|grep Domain`"10 echo $DOMAIN11 echo $LOCALIP12 #sed -e ‘s/Domain = 10.0.66.66/Domain = 10.0.73.15/g‘ $SCC_PATH13 sed -i ‘s/‘"${DOMAIN}"‘/Domain = ‘"${LOCALIP}"‘/g‘ $SCC_PATH14 }15 16 17 modify_conf()18 {19 modify_scc20 }21 22 modify_conf23 24 exit 0
conf.sh
說明:sed -i ‘s/‘"${DOMAIN}"‘/Domain = ‘"${LOCALIP}"‘/g‘ $SCC_PATH
由於宏定義DOMAIN和LOCALIP在命令中使用$DOMAIN和$LOCALIP無法使用,需要使用‘"${DOMAIN}"‘和‘"${LOCALIP}"‘,使執行指令碼時能夠替換
1 #!/bin/sh 2 MENULST="/JONET_boot/menu.lst" 3 SCC_PATH="/JONET/bin/SCC/CenterServer.config" 4 LOCALIP="`awk -F ‘,‘ ‘{print $2}‘ $MENULST |grep .`"; 5 echo $LOCALIP 6 7 modify_scc() 8 { 9 DOMAIN="`cat $SCC_PATH|grep Domain`"10 echo $DOMAIN11 echo $LOCALIP12 sed -i ‘s/‘"${DOMAIN}"‘/Domain = ‘"${LOCALIP}"‘/g‘ $SCC_PATH13 }14 15 modify_conf()16 {17 modify_scc18 }19 20 modify_conf21 22 exit 0
conf.sh