I have 4 instances of Tomcat to serve a JSP application. Every now and then I have to restart them all (when I recompile a class, for instance). But every time I have to restart their services one by one:

sudo service tomcat71 restart
sudo service tomcat72 restart
sudo service tomcat73 restart
sudo service tomcat74 restart

How can I put those commandis in a script so to run them all at once?

Thanks in advance!


Try this script:

for num in {71..74}
  sudo service "tomcat$num" restart

You can change the {71..74} sequence if needed.

The same command on a single line:

 for num in {71..74}; do sudo service "tomcat$num" restart; done

(This might be more useful in an interactive shell — quicker to type).

More info:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.