2011-07-21 36 views
1

我在創建一個自動化的腳本6.在安裝新的服務器簡單的Linux腳本

sudo cp "apache-solr-3.3.0/dist/apache-solr-3.3.0.war" "/var/lib/tomcat6/webapps/solr.war" 
sudo cp -R "apache-solr-3.3.0/example/solr/" "/var/lib/tomcat6/solr/" 
sudo cp "solr.xml" "/etc/tomcat6/Catalina/localhost/solr.xml" 
rm -R "apache-solr-3.3.0" 
sudo service tomcat6 restart 

我得到

cp: target `\r' is not a directory 
cp: target `\r' is not a directory 
rm: cannot remove `\r': No such file or directory 
* Usage: /etc/init.d/tomcat6 {start|stop|restart|try-restart|force-reload|status} 

看來,因爲我使用換行符終止命令(上Solr的問題就好像它是一個windows bat文件)。如何在單個文件中運行多個命令

回答

7

您可能正在腳本中使用Windows換行符。使用dos2unix實用程序將它們轉換爲Linux換行符:dos2unix your_script.sh

+0

或者用dos2unix我用貓oldfild | tr'\ n \ r''\ n \ n'>> newfile –

2

問題似乎是您的shell腳本具有窗口行結尾(\r\n)。 Bash只關心\n,因此\r被解釋爲是該命令的一部分。

您需要將行結束符更改爲unix(僅限\n)。 dos2unix可以爲你做到這一點。

1

更正腳本中的行尾以使用unix標準\n。不幸的是,你也有\r,它看起來像shell將它們作爲最後的參數傳遞給它們。