Last active
August 29, 2015 14:24
-
-
Save joxl/fd6ba416809a4eef4257 to your computer and use it in GitHub Desktop.
Check status of private webapp listening on remote port
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import sys | |
from subprocess import Popen | |
from urlparse import urlunsplit | |
def main(): | |
params = json.load(sys.stdin) | |
urlparts = [] | |
for name in ["scheme", "netloc", "path", "query", "fragment"]: | |
param = params.pop(name, "") | |
if name in ["scheme", "netloc"]: | |
assert param, "missing %s parameter" % (name,) | |
urlparts.append(param) | |
assert not params, params | |
url = urlunsplit(urlparts) | |
# $ curl -sL -o /dev/null -w "%{http_code} %{url_effective}\n" "http://shop.kwsi.co" | |
# 200 http://shop.kwsi.co/ | |
cmd = ["curl", "-sLo", "/dev/null", "-w", r"%{http_code} %{url_effective}\n", url] | |
proc = Popen(cmd, stdout=sys.stdout, stderr=sys.stderr) | |
sys.exit(proc.wait()) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment