BYTESLIP ← Back
Knowledge Base // Tutorial 60 · Termux

Schedule Scripts in Termux With termux-job-scheduler

Difficulty: Medium ~15–25 min Termux · F-Droid

Android isn’t a desktop cron host. The Termux wiki’s supported, Tasker-free path is termux-job-scheduler from Termux:API: it hooks Android’s JobScheduler so scripts can run periodically with battery/network constraints. Classic crond exists in some packages but fights Doze—prefer the API for reliability.

termux-job-schedulerpkg install termux-apitermux-job-scheduler --script … --period-msmin 15 min on Android N+MEDIUM · JOB SCHEDULER
Checklist // Before You Start

What You Need

Walkthrough // Steps

API add-on → script → schedule

  1. Step 1: Install Termux:API (app + package)

    In F-Droid, install Termux:API. Then in Termux:

    pkg update
    pkg install termux-api
    termux-job-scheduler --help | head

    Wiki lists termux-job-scheduler among Termux:API commands: schedule a script later or periodically.

  2. Step 2: Write a tiny test script

    mkdir -p ~/scripts
    cat > ~/scripts/heartbeat.sh << 'EOF'
    #!/data/data/com.termux/files/usr/bin/bash
    echo "$(date -Iseconds) heartbeat" >> ~/heartbeat.log
    EOF
    chmod +x ~/scripts/heartbeat.sh
    ~/scripts/heartbeat.sh
    cat ~/heartbeat.log

    Run it once by hand before scheduling so failures aren’t “invisible.”

  3. Step 3: Schedule with termux-job-scheduler

    On Android N+, the minimum period is 900000 ms (15 minutes). Example: every 15 minutes, prefer unmetered Wi‑Fi, survive reboot:

    termux-job-scheduler \
      --job-id 1 \
      --script ~/scripts/heartbeat.sh \
      --period-ms 900000 \
      --network unmetered \
      --persisted true

    Other useful flags (from the tool’s help): --charging, --battery-not-low, --storage-not-low. Timing is approximate—Android batches jobs for battery.

  4. Step 4: List pending jobs

    termux-job-scheduler --pending

    After a while, check cat ~/heartbeat.log for new lines. If nothing appears: confirm Termux:API is installed from F-Droid, battery optimization isn’t killing Termux immediately, and the period isn’t below 15 minutes.

  5. Step 5: Cancel when done

    termux-job-scheduler --cancel --job-id 1
    # or
    termux-job-scheduler --cancel-all
Note // Why not cron?

Desktop-style crond needs Termux kept alive (wake locks, disabled battery optimization) and still loses to aggressive OEMs. termux-job-scheduler is the wiki-listed Termux:API tool built for Android’s scheduler. Exact wall-clock “3:17 AM” cron expressions aren’t what JobScheduler guarantees—use intervals + constraints instead.

Sources // Verified
← All Tutorials Termux tutorials Install Termux