diff options
-rw-r--r-- | .github/workflows/ping-he-tb.yml | 25 | ||||
-rw-r--r-- | .github/workflows/scheduled-tasks.yml | 15 | ||||
-rwxr-xr-x | ping-he-tb | 45 |
3 files changed, 70 insertions, 15 deletions
diff --git a/.github/workflows/ping-he-tb.yml b/.github/workflows/ping-he-tb.yml new file mode 100644 index 0000000..abb862b --- /dev/null +++ b/.github/workflows/ping-he-tb.yml @@ -0,0 +1,25 @@ +name: ping-he-tb +run-name: ping-he-tb +on: + schedule: + - cron: '*/5 * * * *' + workflow_dispatch: +jobs: + Do-snapshot: + name: "ping-he-tb" + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + with: + ref: 'data' + - name: Run ping-he-tb + run: | + mkdir -p ping-data + ./ping-he-tb | tee "ping-data/$(date -uIns)" + - name: Do commit + run: | + git config --global user.name 'Snapshot Automation Bot' + git config --global user.email '_@users.noreply.github.com' + git add ping-he-tb + git commit -sm 'ping-data commit' + git push diff --git a/.github/workflows/scheduled-tasks.yml b/.github/workflows/scheduled-tasks.yml deleted file mode 100644 index 5ff2cb4..0000000 --- a/.github/workflows/scheduled-tasks.yml +++ /dev/null @@ -1,15 +0,0 @@ -name: Test -run-name: Tests -on: - schedule: - - cron: '*/5 * * * *' - workflow_dispatch: -jobs: - Do-snapshot: - name: "test" - runs-on: ubuntu-latest - steps: - # - uses: actions/checkout@v3 - - name: Run - run: | - curl http://github-actions-test.dev.snart.me/ diff --git a/ping-he-tb b/ping-he-tb new file mode 100755 index 0000000..b87f8b2 --- /dev/null +++ b/ping-he-tb @@ -0,0 +1,45 @@ +#!/bin/bash +main () { + cd "$TMPDIR" + + set +e + LIST=$(curl -sSL 'https://tunnelbroker.net/status.php' | + grep -Eo 'title="[0-9.]+"' | + grep -Eo '([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3})') + set -e + + for addr in $LIST + do + ping -qnc4 "$addr" > "$addr" & + done + + set +e # ignore non-zero exit code from ping command + for addr in $LIST + do + wait + done + set -e + + for addr in $LIST + do + avg=$(echo $(cat "$addr" | + grep -Eo 'rtt min/avg/max/mdev = [0-9.]+/[0-9.]+/[0-9.]+/[0-9.]+' | + grep -Eo '[0-9.]+') | + awk '{print $2}') + if [ -z "$avg" ]; then + avg="inf" + fi + + echo "$avg $addr" + done | sort -g +} + +set -e +TMPDIR=$(mktemp -d) +set +e + +main & wait +ec="$?" + +rm -rf "$TMPDIR" +exit "$ec" |