Skip to content

Instantly share code, notes, and snippets.

@golonzovsky
Last active April 23, 2017 17:03
Show Gist options
  • Save golonzovsky/ae9cb92c020f0b8833519447b7471281 to your computer and use it in GitHub Desktop.
Save golonzovsky/ae9cb92c020f0b8833519447b7471281 to your computer and use it in GitHub Desktop.
undeploy all apps from tomcat using tomcat-manager. One liner! Power of pipes!

Command

curl --user user:pass -s https://tomcatHost/manager/text/list | tail -n+2  | cut -d':' -f1 | grep -v "manager" | xargs -L1 -I% curl --user user:pass -s https://tomcatHost/manager/text/undeploy?path=%

Explanation

  • curl --user user:pass -s https://tomcatHost/manager/text/list get list of apps
OK - Listed applications for virtual host localhost
/develop:running:0:develop
/feature-actuator:running:0:feature-actuator
/manager:running:0:manager
  • tail -n+2 remove first line
/develop:running:0:develop
/feature-actuator:running:0:feature-actuator
/manager:running:0:manager
  • cut -d':' -f1 get context path - first block before colon /develop:running:0:develop. -d':' defines colon separator. -f1 first column.
/develop
/feature-actuator
/manager
  • grep -v "manager" keep manager. -v inverts grep
/develop
/feature-actuator
  • xargs -L1 -I% curl --user user:pass -s https://tomcatHost/manager/text/undeploy?path=% pass result to curl to undeploy each of resulting contexts. -L1 to call curl for each line. -I% to have a % placeholder
@golonzovsky
Copy link
Author

golonzovsky commented Apr 23, 2017

in the same way - update all docker images:
docker images | grep -v REPO | cut -d' ' -f1 | xargs -L1 docker pull

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment