Setup guide

Back to Docs

How to monitor a Python or Bash script with PulseWatch

A scheduled script needs a way to report what happened. PulseWatch records when your job starts, succeeds or fails, and its external watchdog checks for missed runs and jobs that take too long.

The free Monitor my script generator creates a wrapper around your existing Python function or Bash command. It generates code in your browser; your private monitoring URL stays in your job's environment.

1. Create a monitor

Sign up to PulseWatch and create a monitor for your job. The free plan includes two monitors, with no credit card required.

Choose settings that match the job:

Monitor schedule settings
SettingWhat to enter
Expected intervalHow often the job should run, such as daily.
Grace periodExtra time for normal scheduler delays and queueing.
Maximum runtimeHow long a started job may take before it is considered stuck.

For example, a daily report that usually takes 20 minutes might use a daily interval, two-hour grace and one-hour maximum runtime. Adjust these to the delays you actually observe.

Copy the monitor's private base ping URL. The wrapper adds /start, /success and /fail itself. Treat the URL as a credential and keep it out of public code and logs.

2. Set the private URL in your environment

For a local test in Bash, this prompts for the URL without displaying it or putting it in your command history:

read -r -s -p "Private PulseWatch base URL: " PULSEWATCH_PING_URL
printf '\n'
export PULSEWATCH_PING_URL

This sets the variable for the current terminal and commands launched from it. Configure the same variable through your scheduler or hosting platform's private environment settings for unattended runs.

3. Generate and add the wrapper

Open Monitor my script, choose your language and select Copy code.

Python

Enter your existing function name, such as generate_report. Keep its definition or import above the generated wrapper, and replace the original standalone function call with the wrapper. Then run your script as usual:

python3 report.py

The generator calls the function with no arguments. If your function needs arguments, put that call inside a small function that takes no arguments and enter its name instead. The wrapper uses Python's standard library.

Bash

Save the generated code as monitor-job.sh in your job's folder. It requires Bash and curl. Run your existing command through it:

bash monitor-job.sh python3 report.py

You can pass the command's usual arguments after it. The wrapper preserves those arguments and returns the command's exit status. Keep the generated status-handling code as provided; adding set -e can bypass failure reporting.

4. Complete one successful run

Run the wrapped job and check its history in PulseWatch. You should see a start followed by a successful completion. This establishes the baseline for missed-run monitoring.

A monitor with no pings sends no alerts, and the first healthy watchdog check is silent. Later unhealthy transitions and recovery can trigger emails.

An ordinary Python exception or non-zero Bash exit reports failure while preserving the original job outcome. Monitoring requests have a five-second timeout; a failed ping does not replace that outcome.

For scheduled runs, keep the scheduler pointing at your updated Python script, or replace the original Bash command with the wrapper command. Confirm that the scheduler receives PULSEWATCH_PING_URL.

5. Check useful output and alerts

Put an output check inside your job before it returns successfully. For example, if an empty daily export means failure, raise an exception or exit non-zero when the export contains no records. Choose a rule that fits your task; PulseWatch records the outcome your code reports.

After a successful baseline, use a disposable test job to report an intentional failure, check the alert, then run it successfully to check recovery.

Detected monitoring states
StateWhat PulseWatch detects
FAILEDThe latest completed run reported failure, provided the monitor is not missing or stuck.
MISSINGNo later success arrived within the expected interval plus grace, measured from the start of the latest successful run.
STUCKA started run remains unfinished beyond its maximum runtime.

Alerts arrive on the next applicable plan check, every 5–30 minutes. Use one monitor for one active job at a time: a new start supersedes an older unfinished run.