← Back to Pushany 日本語

⏱️ Notify from a script

How to get a notification on your phone when a backup or a long job finishes, or when a GitHub Actions run completes. All it takes is sending to a webhook URL with curl.

Create a URLWhen a job finishescronGitHub ActionsGood to know

Create a URL

  1. In Pushany, go to Settings → Integrations → Webhooks, select “Create URL” and enter a name (for example, Server).
  2. Copy the URL that appears. It’s shown only once.

The examples below keep the URL in the environment variable PUSHANY_URL.

export PUSHANY_URL=""

⚠️ Anyone who knows the URL can send to it. Don’t write it in your scripts; keep it in an environment variable or in GitHub Secrets.

Get notified when a job finishes

Send text in the body with POST, and it arrives in your tray with a notification.

curl -d "Build finished" "$PUSHANY_URL"

Add it after a long command to be notified when it’s done. To send a different message for success and failure, write:

./backup.sh && curl -d "Backup completed" "$PUSHANY_URL" \
  || curl -d "Backup failed" "$PUSHANY_URL"

Send JSON to set a title and a message separately. Include a URL to open that page when you tap the notification.

curl -H "Content-Type: application/json" \
  -d '{"title": "Server", "message": "Free disk space is below 10%", "url": "https://example.com/status"}' \
  "$PUSHANY_URL"

Run it on a schedule with cron

Add it to the end of a cron job to know when it finished or failed.

0 3 * * * /home/me/backup.sh && curl -s -d "Nightly backup completed" ""

cron may not load the environment variables from your login shell. If so, read the URL from a file, for example.

Get notified about GitHub Actions results

  1. On GitHub, open Settings → Secrets and variables → Actions for the project you want notifications from, select “New repository secret” and save the URL with the name PUSHANY_URL.
  2. Add this step at the end of your workflow. Whether the run succeeds or fails, you get the workflow name and the result. Tap the notification to open that run.
      - name: Notify my phone
        if: always()
        env:
          PUSHANY_URL: ${{ secrets.PUSHANY_URL }}
        run: >-
          curl -sS
          --data-urlencode "title=${{ github.workflow }}: ${{ job.status }}"
          --data-urlencode "message=${{ github.repository }} (${{ github.ref_name }})"
          --data-urlencode "url=${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
          "$PUSHANY_URL"

To be notified only when a run fails, change if: always() to if: failure().

Good to know