Real-world automation scripts that run on a schedule and notify you when something matters. Each workflow includes the full script, scheduler setup (cron + macOS launchd), realistic output, and customization tips.
All scripts assume you’ve already authenticated with octav auth set-key YOUR_API_KEY. See Authentication for setup. For basic CLI usage and one-liners, see Examples.
Checks a Solana wallet for unclaimed airdrops every day at 2pm. Sends a macOS desktop notification when new airdrops are found and logs results for history.
Monitors wallets every 10 minutes for new activity. Tracks state to avoid duplicate alerts and supports both macOS notifications and Slack webhooks.
Copy
#!/bin/bash# tx-watchdog.sh — Detect new transactions and send alertsADDR="0x742d35Cc6634C0532925a3b844Bc9e7595f2bD68"STATE_DIR="$HOME/.octav/state"STATE_FILE="$STATE_DIR/tx-watchdog-last-tx.txt"LOG_FILE="$HOME/.octav/logs/tx-watchdog.log"# Optional: set to your Slack webhook URL, or leave empty for macOS notifications onlySLACK_WEBHOOK=""mkdir -p "$STATE_DIR" "$(dirname "$LOG_FILE")"# Get the last known transaction hashLAST_SEEN=""[ -f "$STATE_FILE" ] && LAST_SEEN=$(cat "$STATE_FILE")# Fetch recent transactionsRESULT=$(octav transactions get --addresses "$ADDR" --limit 10 --raw 2>&1)if [ $? -ne 0 ]; then echo "[$(date)] ERROR: $RESULT" >> "$LOG_FILE" exit 1fi# Get the latest transaction hashLATEST_TX=$(echo "$RESULT" | jq -r '.transactions[0].hash // empty')if [ -z "$LATEST_TX" ]; then echo "[$(date)] No transactions found" >> "$LOG_FILE" exit 0fi# Compare with last seenif [ "$LATEST_TX" = "$LAST_SEEN" ]; then echo "[$(date)] No new transactions" >> "$LOG_FILE" exit 0fi# New transactions found — collect all new onesNEW_TXS=$(echo "$RESULT" | jq -r --arg last "$LAST_SEEN" ' .transactions | if $last == "" then .[:5] else [.[] | select(.hash != $last)] end | .[] | "\(.type) \(.amount) \(.token_symbol) ($\(.value_usd)) on \(.chain) — \(.date)"')NEW_COUNT=$(echo "$RESULT" | jq --arg last "$LAST_SEEN" ' .transactions | if $last == "" then .[:5] else [.[] | select(.hash != $last)] end | length')# Update stateecho "$LATEST_TX" > "$STATE_FILE"# Logecho "[$(date)] $NEW_COUNT new transaction(s) detected:" >> "$LOG_FILE"echo "$NEW_TXS" >> "$LOG_FILE"# Send macOS notificationosascript -e "display notification \"$NEW_COUNT new transaction(s) on ${ADDR:0:6}...${ADDR: -4}\" with title \"Octav Transaction Alert\""# Send Slack notification if webhook is configuredif [ -n "$SLACK_WEBHOOK" ]; then SLACK_MSG=$(echo "$NEW_TXS" | sed 's/"/\\"/g' | paste -sd '\n' -) curl -s -X POST "$SLACK_WEBHOOK" \ -H 'Content-Type: application/json' \ -d "{\"text\": \"*Transaction Alert* — ${ADDR:0:6}...${ADDR: -4}\n\`\`\`$SLACK_MSG\`\`\`\"}" \ > /dev/nullfi
Sample alert output:
Copy
[2025-01-15 14:30:01] 2 new transaction(s) detected:swap 2.5 ETH ($5875.00) on ethereum — 2025-01-15transfer 1000.0 USDC ($1000.00) on ethereum — 2025-01-15
cron
launchd (macOS)
Copy
# Run every 10 minutes*/10 * * * * /path/to/tx-watchdog.sh
Save as ~/Library/LaunchAgents/fi.octav.tx-watchdog.plist:
Runs at midnight, exports the day’s transactions to a monthly CSV file. Handles pagination for wallets with high daily activity and appends without duplicates.
Copy
#!/bin/bash# nightly-export.sh — Export today's transactions to a monthly CSVADDR="0x742d35Cc6634C0532925a3b844Bc9e7595f2bD68"EXPORT_DIR="$HOME/.octav/exports"TODAY=$(date +%Y-%m-%d)MONTH_FILE="$EXPORT_DIR/transactions-$(date +%Y-%m).csv"mkdir -p "$EXPORT_DIR"# Initialize CSV with header if it doesn't existif [ ! -f "$MONTH_FILE" ]; then echo "date,type,chain,token,amount,value_usd,hash" > "$MONTH_FILE"fi# Fetch today's transactions with paginationOFFSET=0LIMIT=250TOTAL_EXPORTED=0while true; do RESULT=$(octav transactions get \ --addresses "$ADDR" \ --start-date "$TODAY" \ --end-date "$TODAY" \ --limit "$LIMIT" \ --offset "$OFFSET" \ --raw 2>&1) if [ $? -ne 0 ]; then echo "[$(date)] ERROR: $RESULT" >&2 exit 1 fi # Extract transaction count COUNT=$(echo "$RESULT" | jq '.transactions | length') if [ "$COUNT" -eq 0 ]; then break fi # Append to CSV (skip duplicates by checking hash) EXISTING_HASHES="" [ -f "$MONTH_FILE" ] && EXISTING_HASHES=$(cut -d',' -f7 "$MONTH_FILE" | tail -n +2) echo "$RESULT" | jq -r --arg existing "$EXISTING_HASHES" ' .transactions[] | select(.hash as $h | ($existing | split("\n") | index($h)) | not) | [.date, .type, .chain, .token_symbol, .amount, .value_usd, .hash] | @csv ' >> "$MONTH_FILE" NEW_ROWS=$(echo "$RESULT" | jq --arg existing "$EXISTING_HASHES" ' [.transactions[] | select(.hash as $h | ($existing | split("\n") | index($h)) | not)] | length ') TOTAL_EXPORTED=$((TOTAL_EXPORTED + NEW_ROWS)) # If we got fewer than the limit, we've reached the end if [ "$COUNT" -lt "$LIMIT" ]; then break fi OFFSET=$((OFFSET + LIMIT))doneecho "[$(date)] Exported $TOTAL_EXPORTED transaction(s) for $TODAY to $MONTH_FILE"
A wrapper script that checks remaining credits before running any CLI command. Tracks daily consumption and alerts when credits drop below a configurable threshold.
Copy
#!/bin/bash# octav-safe — Credit-aware CLI wrapper# Usage: octav-safe portfolio get --addresses 0x...# Drop-in replacement for `octav` that prevents accidental credit burnCREDIT_THRESHOLD=100 # Warn below this many creditsLOG_DIR="$HOME/.octav/logs"USAGE_LOG="$LOG_DIR/credit-usage.log"mkdir -p "$LOG_DIR"# Check current creditsCREDITS_RESULT=$(octav credits --raw 2>&1)if [ $? -ne 0 ]; then echo "ERROR: Could not check credits — $CREDITS_RESULT" >&2 exit 1fiCREDITS=$(echo "$CREDITS_RESULT" | jq -r '.credits')# Log usageecho "[$(date)] Credits remaining: $CREDITS | Command: octav $*" >> "$USAGE_LOG"# Block if below thresholdif [ "$CREDITS" -lt "$CREDIT_THRESHOLD" ]; then echo "CREDIT GUARD: Only $CREDITS credits remaining (threshold: $CREDIT_THRESHOLD)" echo "" echo " Command blocked: octav $*" echo "" echo " To override, run the command directly with \`octav\` instead of \`octav-safe\`." echo " To adjust the threshold, edit CREDIT_THRESHOLD in $(realpath "$0")" exit 1fi# Show credit count and proceedecho "[octav-safe] Credits: $CREDITS — running: octav $*"octav "$@"
Installation:
Copy
# Make it executable and add to PATHchmod +x /path/to/octav-safeln -s /path/to/octav-safe /usr/local/bin/octav-safe# Now use it as a drop-in replacementoctav-safe portfolio nav --addresses 0x742d35Cc6634C0532925a3b844Bc9e7595f2bD68
CREDIT GUARD: Only 47 credits remaining (threshold: 100) Command blocked: octav portfolio nav --addresses 0x742d... To override, run the command directly with `octav` instead of `octav-safe`. To adjust the threshold, edit CREDIT_THRESHOLD in /Users/you/scripts/octav-safe
Sample daily usage log (credit-usage.log):
Copy
[Mon Jan 15 09:00:01 2025] Credits remaining: 4872 | Command: octav portfolio nav --addresses 0x742d...[Mon Jan 15 09:00:05 2025] Credits remaining: 4871 | Command: octav transactions get --addresses 0x742d...[Mon Jan 15 14:00:01 2025] Credits remaining: 4870 | Command: octav airdrop --address 7xKXtg...[Mon Jan 15 14:10:01 2025] Credits remaining: 4869 | Command: octav transactions get --addresses 0x742d...
Customization tips
Shell alias: Add alias octav="octav-safe" to your ~/.bashrc or ~/.zshrc to protect all commands by default
Daily summary: Add a cron job that parses the usage log and reports daily consumption — grep "$(date +%Y-%m-%d)" "$USAGE_LOG" | wc -l gives you the day’s command count
Tiered warnings: Add a second threshold (e.g., 500) that prints a warning but still allows the command to run
macOS uses launchd instead of cron for scheduled tasks. While cron works on macOS, launchd is the native scheduler and handles sleep/wake correctly — your task runs after waking up even if the Mac was asleep at the scheduled time.
# Check launchd's own logslog show --predicate 'subsystem == "com.apple.xpc.launchd"' --last 1h | grep fi.octav# Check your script's outputcat /tmp/your-script.stdoutcat /tmp/your-script.stderr
Common pitfall: launchd doesn’t source your shell profile. If octav isn’t found, use the full path (/usr/local/bin/octav or wherever it’s installed). Find it with which octav.