Ask Your Question

Replace tomcat port using sed command

asked 2014-11-20 12:18:17 -0600

Rajasekar Ramasamy gravatar image

updated 2014-11-20 12:21:15 -0600


I want to replace the tomcat default port number from 8080 to 80 by using the sed command. Please check the below command which I have used.

command => "sed -i 's|<Connector port="8080"|<Connector port="80"|g' /usr/share/comcat6/server.xml",

The above command is not working due to the double quotes present in the port number "8080". Please help me to resolve the issue.

edit retag flag offensive close merge delete


If you are using puppet why don't you make this a template and change the port there(or using modify this file and copy the file from puppet)

Manula Waidyanatha gravatar imageManula Waidyanatha ( 2014-11-21 03:20:53 -0600 )edit

3 Answers

Sort by ยป oldest newest most voted

answered 2014-11-21 09:22:26 -0600

rnelson0 gravatar image

You need to escape the double quotes with a \ character. i.e.

command => "sed -i 's|<Connector port=\"8080\"|<Connector port=\"80\"|g' /usr/share/comcat6/server.xml",

You will find that this is sometimes tricky and if you don't get it right but it's valid DSL, bad things may happen to the system when puppet runs. You can always put 'echo' before the command so it's non-destructive and test that way. Hopefully you don't need to - you can test it interactively at the CLI, use rspec, etc. - but it's a nice last resort option to have hanging around. Ex:

command => "echo sed -i 's|<Connector port=\"8080\"|<Connector port=\"80\"|g' /usr/share/comcat6/server.xml",
edit flag offensive delete link more


Thanks. Your solution is working fine.

Rajasekar Ramasamy gravatar imageRajasekar Ramasamy ( 2014-11-29 21:08:33 -0600 )edit

answered 2014-11-20 19:32:22 -0600

lupin gravatar image

This is not even a puppet question, if you only need to change the 8080 to 80 this will do,

root@puppet:~# echo '<Connector port="8080">' > /tmp/server.xml
root@puppet:~# cat /tmp/server.xml
<Connector port="8080">
root@puppet:~# sed -i 's#8080#80#' /tmp/server.xml
root@puppet:~# cat /tmp/server.xml
<Connector port="80">
edit flag offensive delete link more

answered 2014-11-21 03:16:34 -0600

jonn gravatar image

This is one of the problems with doing Exec[sed] and friends - getting the quoting right is a nightmare :)

You might want to consider using the puppetlabs-tomcat module from the forge - it is pretty great, and it supports exactly what you're doing here:

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-11-20 12:18:17 -0600

Seen: 1,558 times

Last updated: Nov 21 '14