Marty Trenouth
Marty Trenouth

Reputation: 3752

simple linux script

I'm having problems creating an automated script to isntall solr on a new server

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

I get

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}

It seems because I use line breaks to terminate the commands (as if it were a windows bat file). How do I run multiple commands in a single file

Upvotes: 1

Views: 1376

Answers (3)

Karoly Horvath
Karoly Horvath

Reputation: 96306

Correct the line endings in your script to use the unix standard \n. Unfortunately you have \rs there as well and it looks like the shell passes them as last arguments.

Upvotes: 1

Chris Eberle
Chris Eberle

Reputation: 48795

The issue appears to be that your shell script has windows line endings (\r\n). Bash only cares about the \n and so the \r is interpreted as being a part of the command.

You need to change the line endings to unix (\n only). dos2unix can do this for you.

Upvotes: 2

user500944
user500944

Reputation:

You are probably using Windows line breaks in your script. Convert them to Linux line breaks with the dos2unix utility: dos2unix your_script.sh

Upvotes: 7

Related Questions