2015-12-04 99 views
-1

嗨我想在單個文件(cinder.conf)上一次使用多個sed命令。我的shell文件(test.sh)看起來像在使用SED時Shell腳本出錯

sed -i '/[DEFAULT]/s/$/\nrpc_backend = rabbit\nauth_strategy = keystone\nmy_ip = INPUTREQ\nverbose = True\nenabled_backends = lvm\nglance_host = controller/' /etc/cinder/cinder.conf 

sed -i '/[oslo_messaging_rabbit]/s/$/\nrabbit_host = controller\nrabbit_userid = openstack\nrabbit_password = 1234/' /etc/cinder/cinder.conf 

和我原來的輸出文件看起來

[DEFAULT] 

[oslo_messaging_rabbit] 

當我試圖執行shell文件(test.sh)輸出看起來像

[DEFAULT] 
rpc_backend = rabbit 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 
auth_strategy = keystone 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 
my_ip = INPUTREQ 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 
verbose = True 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 
enabled_backends = lvm 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 
glance_host = controller 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 

[oslo_messaging_rabbit] 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 

但是當我試圖在原始文件(cinder.conf)上執行單個SED命令時它的工作完美。只有當我一次使用多個SED命令購買運行test.sh文件時,我的原始文件如上所示輸出。我正在使用Centos。我不熟悉腳本。請通過錯誤。

我的方案是添加幾行到cinder.con文件(使用shell腳本)。最終的輸出想

[DEFAULT] 
rpc_backend = rabbit 
auth_strategy = keystone 
my_ip = INPUTREQ 
verbose = True 
enabled_backends = lvm 
glance_host = controller 

[oslo_messaging_rabbit] 
rabbit_host = controller 
rabbit_userid = openstack 
rabbit_password = 1234 

回答

2

逃生[]\

sed -i '/\[DEFAULT\]/s/$/\nrpc_backend = rabbit\nauth_strategy = keystone\nmy_ip = INPUTREQ\nverbose = True\nenabled_backends = lvm\nglance_host = controller/' /etc/cinder/cinder.conf 

sed -i '/\[oslo_messaging_rabbit\]/s/$/\nrabbit_host = controller\nrabbit_userid = openstack\nrabbit_password = 1234/' /etc/cinder/cinder.conf 
+0

由於一噸...它working..I有這些字符({)和(:)和(' )我應該使用所有這些角色的逃跑嗎? – Geetha