Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion scripts/crypto-price
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,20 @@ COIN="${1:-BTC}"
SYMBOL="${COIN^^}USDT"
API_URL="https://api.binance.com/api/v3/ticker/price?symbol=${SYMBOL}"

echo "Fetching price for $COIN..."
echo "Fetching price for $COIN..."

# TODO: Use `curl -s` to fetch the JSON from $API_URL.
# The JSON looks similar to: {"symbol":"BTCUSDT","price":"63000.00000000"}
# Use `grep`, `sed`, `awk`, or `jq` (if installed) to extract just the exact price number.
# Print the output in this format: "Current price of $COIN is: $X.XX"
RESPONSE=$(curl -s "$API_URL")
PRICE=$(echo "$RESPONSE" | grep -oP '"price":"\K[^"]+')

if [ -z "$PRICE" ]; then
echo "Failed to fetch price."
exit 1
fi

echo "Current price of $COIN is: $PRICE"


8 changes: 6 additions & 2 deletions scripts/disk-alert
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ THRESHOLD=90
# Example starting point:
# USAGE=$(df -h / | awk 'NR==2 {print $5}')
# Next, remove the '%' sign using `tr -d '%'` so you have a plain integer.
USAGE=""
USAGE=$(df -h / | awk 'NR==2 {print $5}' | tr -d '%')

if [ -z "$USAGE" ]; then
echo "Could not fetch disk usage, please implement the TODO!"
Expand All @@ -21,4 +21,8 @@ echo "Current root disk usage is at $USAGE%"
# TODO: Check if $USAGE is greater than or equal to $THRESHOLD.
# If it is, echo a "WARNING: Disk space low!" message.
# If not, echo an "All good: Plenty of space." message.

if [ "$USAGE" -ge "$THRESHOLD" ]; then
echo "WARNING: Disk space low!"
else
echo "All good: Plenty of space."
fi