0

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!

1 Answer 1

2

Try this script:

#!/bin/bash
for num in {71..74}
do
  sudo service "tomcat$num" restart
done

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:

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .