1. 程式人生 > >修改配置檔案指令碼

修改配置檔案指令碼

###made by h###
echo ---------------------------------
#篩出本機IP並存為變數
        IP=`ifconfig  | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;
        echo 本機IP為:::
        echo $IP

echo ---------------------------------
echo [開始修改datasource.conf配置檔案]
echo ---------------------------------	
sleep 2

cd /opt/server/web/ms/etc
#cp datasource.conf.templ datasource.conf
#eval sed用於shell中執行sed方式
eval sed -i 's/localhost/"$IP"/' datasource.conf
#將jdbc.user=後面的替換為root
#將jdbc.password=後面的替換為abc123+
sed -i "s/\(jdbc.user=\)\S\S*/\1root/" datasource.conf
sed -i "s/\(jdbc.password=\)\S\S*/\1abc123+/" datasource.conf 
echo [預設修改為root/abc123+ 需要自定義修改請取消下方註釋]

#echo 輸入本機資料庫賬號:::
#read sqluser
#echo 輸入資料庫賬號為:::$sqluser
#sed -i "s/\(jdbc.user=\)\S\S*/\1$sqluser/" datasource.conf
#echo ---------------------------------
#echo 輸入本機資料庫密碼:::
#read sqlpass
#echo 輸入資料庫密碼為:::$sqlpass
#sed -i "s/\(jdbc.password=\)\S\S*/\1$sqlpass/" datasource.conf
echo ---------------------------------

sleep 5
#顯示第3行至第6行
cat /opt/server/web/ms/etc/datasource.conf|head -n 6 | tail -n +3
echo ---------------------------------

echo ---------------------------------
echo [開始修改ms-config.conf配置檔案]
echo ---------------------------------	
sleep 5
sed -i "s/\(MS_IP=\)\S\S*/\1$IP/" ms-config.conf
cat /opt/server/web/ms/etc/ms-config.conf|head -n 8 | tail -n +8

echo ---------------------------------
echo [ms-config.conf中只修改了MS_IP 如需修改其他請取消和自定義下方註釋]
echo 附加修改項:::
echo

#echo 輸入LC_IP:::
#read lc
#echo 輸入LC_IP為:::$lc
#sed -i "s/\(LC_IP=\)\S\S*/\1$lc/" ms-config.conf
#echo

#echo 輸入AS_FOREIGN_IP:::
#read as1
#echo 輸入AS_FOREIGN_IP為:::$as1
#sed -i "s/\(AS_FOREIGN_IP=\)\S\S*/\1$as1/" ms-config.conf
#echo

#echo 輸入AS_WEB_IP:::
#read as2
#echo 輸入AS_IP為:::$as2
#sed -i "s/\(AS_WEB_IP=\)\S\S*/\1$as2/" ms-config.conf
#echo

#echo 輸入AS_WEB_PORT:::
#read as3
#echo 輸入AS_WEB_PORT為:::$as3
#sed -i "s/\(AS_WEB_PORT=\)\S\S*/\1$as3/" ms-config.conf
#echo

#echo 輸入AS_CONFIG_IP:::
#read as4
#echo 輸入AS_CONFIG_IP為:::$as4
#sed -i "s/\(AS_CONFIG_IP=\)\S\S*/\1$as4/" ms-config.conf
#echo

echo ---------------------------------
echo -e "\033[32mFinish[MS配置檔案已修改]\033[0m"	
echo ---------------------------------