-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcheck-urls.sh
executable file
·40 lines (35 loc) · 1.06 KB
/
check-urls.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
#!/bin/zsh
SCRIPT_NAME="$(basename $0)"
# Main function to process URLs from standard input
main() {
# Function to display usage help
usage() {
echo "Usage: echo 'URLs' | $SCRIPT_NAME"
echo " cat urls.txt | $SCRIPT_NAME"
echo " pbpaste | $SCRIPT_NAME"
echo
echo "This script checks the HTTP status codes for URLs provided via standard input."
echo "It prints each URL along with its HTTP status code."
echo
echo "No options are needed to run this script, but you can use -h for this help message."
exit 1
}
# Parse command-line arguments for any help request
while [[ "$#" -gt 0 ]]; do
case $1 in
-h|--help) usage ;;
*) echo "Unknown parameter: $1"; usage ;;
esac
shift
done
# Read URLs from standard input and check each one
echo "Fetching HTTP status codes for URLs..."
while read -r url; do
if [ ! -z "$url" ]; then
urlstatus=$(curl -o /dev/null -s -w "%{http_code}" "$url")
echo "$url $urlstatus"
fi
done
}
# Run the main function with all passed arguments
main "$@"