Schedule Scripts in Termux With termux-job-scheduler
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.
What You Need
- F-Droid Termux already working.
- Termux:API app from F-Droid + package
termux-api. - A script you’re allowed to run on your device (logging, backups of your files, reminders)—not anything that targets other people’s systems.
API add-on → script → schedule
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-scheduleramong Termux:API commands: schedule a script later or periodically.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.”
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.Step 4: List pending jobs
termux-job-scheduler --pending
After a while, check
cat ~/heartbeat.logfor 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.Step 5: Cancel when done
termux-job-scheduler --cancel --job-id 1 # or termux-job-scheduler --cancel-all
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.
- Termux:API (includes termux-job-scheduler): wiki.termux.com/wiki/Termux:API
- Addons (F-Droid matching): wiki.termux.com/wiki/Addons