They told me Android couldn’t automate—Termux Crontab proved them wrong.
Back when I first dove into the world of open source, I was sitting in a crowded university lab, wrestling with a stubborn script that refused to run at the same time every day.
My eyes darted between the clock on my phone and the blinking cursor on my terminal, and I realized that true freedom isn’t just about access to code—it’s about the power to bend technology to your will.
That night, I discovered Termux Crontab. In a few simple commands, I transformed my Android device into a fully automated, always-on assistant—no proprietary lock-in, no closed doors, just pure FOSS ingenuity.
In this guide, you’ll learn how to harness that same open-source spirit to schedule your very first cron job on Termux.
Let’s embrace the ethos of collaboration and control—read on and start automating your Android world today!
What is Cron?
Cron is a time-based job scheduler in Unix-like operating systems. Users schedule jobs (commands or scripts) to run periodically at fixed times, dates, or intervals. It’s a powerful utility for automating maintenance and administration tasks.
· · ─ ·𖥸· ─ · ·
Basic Cron Syntax
The cron
syntax is straightforward once you get the hang of it. A crontab
file contains one job per line, with the following structure:
* * * * * command_to_execute
| | | | |
| | | | +-- Day of the week (0 - 7) (Sunday=0 or 7)
| | | +---- Month (1 - 12)
| | +------ Day of the month (1 - 31)
| +-------- Hour (0 - 23)
+---------- Minute (0 - 59)
Each asterisk (*
) represents a time field and can be replaced with specific values to define when the command should run. For example, if you want a command to run every day at 2:30 AM, you would use:
30 2 * * * command_to_execute
· · ─ ·𖥸· ─ · ·
Demystifying Cron Syntax Fields
Cron schedules are defined by five fields—minute, hour, day of month, month, and day of week—separated by spaces. Each field accepts:
- A single value (e.g.,
5
→ “at :05”) - A range (
1-5
→ “days 1 through 5”) - A list (
0,30
→ “at :00 and :30”) - A step (
*/15
→ “every 15 minutes”)
For example,
30 7 * * 1-5 my_script.sh
runs my_script.sh every weekday at 7:30 AM. Play with an online cron expression tester (search “cron expression tester”) to get instant feedback on your schedules.
5.2 Setting File Permissions & Locations
Your cron job must point to an executable script. To prepare:
Store your scripts under (create if missing).
~/scripts/
Make executable:
chmod +x ~/scripts/backup.sh
Absolute paths only: cron won’t respect your $PATH
, so always call
/data/data/com.termux/files/home/scripts/backup.sh.
With correct permissions and explicit paths, Termux Crontab can reliably launch any script without “permission denied” errors.
Setting Up Cron in Termux
1. Install Cron in Termux: If you haven’t already, you’ll need to install the cron package in Termux. You can do this with the following command:
pkg install cronie X
After installation, start the cron service:
crond
Create a Crontab File: To schedule tasks, you’ll need to edit your crontab file. You can create or edit your crontab by typing:
crontab -e
This will open an editor where you can define your cron jobs.
0 5 * * * /path/to/script.sh
Understanding Cron Syntax: Cron jobs follow a specific syntax:
* * * * * command/to/run
Each asterisk represents a time unit (minute, hour, day of month, month, day of week). For example:
This runs script.sh
every day at 5:00 AM.
Running a Bash Script Every 5 Minutes: If you want to run a script every 5 minutes, you can add the following line to your crontab:
*/5 * * * * /path/to/script.sh
Running a Script at a Specific Time: To run a script at a specific time, such as 2:30 PM every day:
30 14 * * * /path/to/script.sh
· · ─ ·𖥸· ─ · ·
Use Case Examples
Sync Files Automatically: Use rsync
to sync directories between your Android device and a server every hour.
0 * * * * rsync -av /source/directory/ /destination/directory
Backup Important Files: Create a backup of critical files every night at midnight.
0 0 * * * tar -czf /backup/location/backup.tar.gz /important/files/
Check for Software Updates: Automatically check for and install package updates daily.
0 2 * * * pkg update && pkg upgrade -y
· · ─ ·𖥸· ─ · ·
Wrapping Up Your First Termux Crontab Job
By now, you’ve:
- Installed and configured Termux Crontab
- Written and tested a basic cron schedule
- Learned troubleshooting tips for common errors
You’re officially on the path from manual nudges to hands-off automation. Imagine what else you could schedule—backups, notifications, even your morning coffee order (okay, maybe not that last one).
· · ─ ·𖥸· ─ · ·
Stay ahead of the curve:
Subscribe to my newsletter for more FOSS-friendly Android tips, step-by-step guides, and community stories.
Join the DevDigest Newsletter »
Leave a Reply