20 / 55 · 19 Linux & Command Line · grep, curl, and jq← prev⊞ allnext →☰ Read as one page
3.5Combining grep, curl, and jq
The real power comes from combining these tools:
# Check API health and alert on non-200
STATUS=$(curl -s -o /dev/null -w "%{http_code}" https://api.example.com/health)
[ "$STATUS" -ne 200 ] && echo "API is down! Status: $STATUS"
# Find all admin users and count them
curl -s https://api.example.com/users | jq '[.[] | select(.role == "admin")] | length'
# Search API response for specific data
curl -s https://api.example.com/products | jq '.[] | select(.name | test(".*phone.*"; "i"))'
# Monitor endpoint response times in a loop
while true; do
TIME=$(curl -s -o /dev/null -w "%{time_total}" https://api.example.com/health)
echo "$(date): ${TIME}s"
sleep 10
done