Skip to content

Commit 906e8f4

Browse files
jesse-cthomaspaulmann
authored andcommitted
Add command to check if a website is up or not
1 parent 026ae6a commit 906e8f4

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed

commands/developer-utils/is-it-up.sh

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#!/bin/bash
2+
3+
# Dependency: requires jq (https://stedolan.github.io/jq/)
4+
# Install via Homebrew: `brew install jq`
5+
6+
# Required parameters:
7+
# @raycast.schemaVersion 1
8+
# @raycast.title Is It Up?
9+
# @raycast.mode compact
10+
# @raycast.packageName Developer Utils
11+
#
12+
# Optional parameters:
13+
# @raycast.icon 🩺
14+
# @raycast.argument1 { "type": "text", "placeholder": "Website" }
15+
#
16+
# Documentation:
17+
# @raycast.description Check if a website is up
18+
# @raycast.author Jesse Claven
19+
# @raycast.authorURL https://github.com/jesse-c
20+
21+
if ! command -v jq &> /dev/null; then
22+
echo "jq is required (https://stedolan.github.io/jq/).";
23+
exit 1;
24+
fi
25+
26+
status_code=$(curl --silent "https://isitup.org/$1.json" | jq '.status_code')
27+
28+
# Sample output:
29+
#
30+
# {
31+
# "domain": "duckduckgo.com",
32+
# "port": 80,
33+
# "status_code": 1,
34+
# "response_ip": "52.142.124.215",
35+
# "response_code": 200,
36+
# "response_time": 0.021
37+
# }
38+
39+
case $status_code in
40+
1) echo "Up: $1"
41+
exit 0
42+
;;
43+
2) echo "Down: $1"
44+
exit 0
45+
;;
46+
3) echo "Invalid domain: $1"
47+
exit 1
48+
;;
49+
*) echo "Unknown status code ($status_code): $1"
50+
exit 1
51+
;;
52+
esac

0 commit comments

Comments
 (0)