forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathis-it-up.sh
executable file
·64 lines (54 loc) · 1.3 KB
/
is-it-up.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# Dependency: requires jq (https://stedolan.github.io/jq/)
# Install via Homebrew: `brew install jq`
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Is It Up?
# @raycast.mode compact
# @raycast.packageName Developer Utils
#
# Optional parameters:
# @raycast.icon 🌐
# @raycast.argument1 { "type": "text", "placeholder": "Website" }
#
# Documentation:
# @raycast.description Check if a website is up
# @raycast.author Jesse Claven
# @raycast.authorURL https://github.com/jesse-c
if ! command -v jq &> /dev/null; then
echo "jq is required (https://stedolan.github.io/jq/).";
exit 1;
fi
# Get the url from the user input
url=$1
# Remove any protocol prefix (http:// or https://)
url=${url#*://}
# Remove any www. prefix
url=${url#www.}
# Remove any trailing slash
url=${url%/}
status_code=$(curl --silent "https://isitup.org/${url}.json" | jq '.status_code')
# Sample output:
#
# {
# "domain": "duckduckgo.com",
# "port": 80,
# "status_code": 1,
# "response_ip": "52.142.124.215",
# "response_code": 200,
# "response_time": 0.021
# }
case $status_code in
1) echo "$1 is up!"
exit 0
;;
2) echo "$1 is down."
exit 0
;;
3) echo "Invalid domain: $1"
exit 1
;;
*) echo "Error: unknown status code ($status_code): $1"
exit 1
;;
esac