diff --git a/scripts/crypto-price b/scripts/crypto-price index 2aa9a16..b48d625 100644 --- a/scripts/crypto-price +++ b/scripts/crypto-price @@ -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" + diff --git a/scripts/disk-alert b/scripts/disk-alert index ab1cc55..e98c85a 100644 --- a/scripts/disk-alert +++ b/scripts/disk-alert @@ -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!" @@ -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