How to Automate Tasks on Android Using Termux — Bash Automation Guide
How to Automate Tasks on Android Using Termux — Bash Automation Guide 2026
- Introduction — Why Automate with Termux?
- Setting Up Termux for Bash Automation
- Writing Your First Bash Script in Termux
- Scheduling Tasks with Cron in Termux
- Practical Automation Scripts You Can Use Today
- Advanced Automation — APIs, Notifications, and More
- Common Errors and Fixes
- Pro Tips for Termux Automation
- Comparison: Termux Automation vs Other Methods
- FAQ
- Conclusion
// 00 — Introduction: Why Automate Tasks on Android Using Termux?
If you've ever wanted to automate tasks on Android without rooting your device, Termux is the single most powerful tool available to you right now. Termux is a free, open-source terminal emulator for Android that gives you access to a full Linux-like environment — and with it, the ability to write and run bash automation scripts directly on your phone. No root required, no special hardware, just your Android device and a willingness to learn.
Think about the things you do repeatedly on your phone or computer. Downloading files at a specific time. Sending yourself reminders. Backing up important data. Checking whether a website is online. Renaming hundreds of files. These are all things that can be automated using bash scripts running inside Termux — and once you set them up, they run on their own while you focus on other things.
Bash automation in Termux isn't just a novelty. It's genuinely useful. Students use it to automate study reminders. Developers use it to run build scripts from their phones while away from their desks. Security learners use it to practice scripting skills in a real Linux environment. Even non-technical users, once they learn the basics, find that automating small tasks saves them significant time every single day.
This guide by Rixon Xavier is written for complete beginners — if you've never opened a terminal before, don't worry. Every command and concept will be explained in plain English. By the time you finish reading this guide, you will know how to write bash scripts, schedule them to run automatically, and build practical automation tools that actually do useful things on your Android device. Let's dive in.
// 01 — Setting Up Termux for Bash Automation
Before you can automate anything, you need a clean, working Termux installation. This section covers everything from first install to making sure you have all the packages needed for bash scripting and task automation.
Step 1: Install and Update Termux
Download Termux from F-Droid at f-droid.org. Once installed, open it. The very first thing you should always do is update the package list and upgrade any outdated packages:
pkg update && pkg upgrade -y
This command does two things. pkg update refreshes the list of available packages from Termux's repositories. pkg upgrade -y installs any updates for packages that are already installed on your system. The -y flag automatically says "yes" to any prompts so you don't have to type it manually.
Step 2: Install Core Tools
For bash automation, you'll need a few essential packages. Install them all at once with this single command:
pkg install -y bash coreutils cronie nano curl wget git
Here's what each package does:
- bash — The shell interpreter that runs your scripts.
- coreutils — Standard Linux tools like
ls,cp,mv,date, and many more. - cronie — The cron daemon, which lets you schedule scripts to run at specific times.
- nano — A simple, beginner-friendly text editor for writing scripts.
- curl — A tool for making web requests, useful for automation that talks to APIs.
- wget — For downloading files from the internet automatically.
- git — For version-controlling your scripts and pulling automation tools from GitHub.
Step 3: Set Up Storage Access
If you want your bash automation scripts to interact with files on your Android device (like the Downloads or Documents folder), you need to grant Termux storage permission:
termux-setup-storage
Android will pop up a permission dialog — tap "Allow". After that, your Android storage is accessible from Termux at the path ~/storage/shared/. This means your scripts can read and write files anywhere on your phone's internal storage.
Verify bash is working
Type bash --version and press Enter. You should see output like GNU bash, version 5.x.x. If you see this, you're ready to start scripting.
// 02 — Writing Your First Bash Script in Termux
A bash script is simply a text file containing a series of commands, exactly the kind you'd type one by one into the terminal, saved so they can be run all at once. Learning to write bash scripts is the foundation of all Termux automation. Let's build your first one from scratch.
Understanding the Shebang Line
Every bash script starts with a special first line called a shebang. It tells the system which interpreter to use to run the file:
#!/data/data/com.termux/files/usr/bin/bash
Note that in Termux, the bash binary lives at a different path than on a standard Linux system. On desktop Linux you'd write #!/bin/bash, but in Termux you must use the path above, otherwise your script won't run correctly.
Creating and Running a Hello World Script
Create the script file
Use nano to create a new file called hello.sh:
nano hello.sh
Type the script content
Inside nano, type the following:
#!/data/data/com.termux/files/usr/bin/bash
echo "Hello from Termux!"
echo "Today's date is: $(date)"
echo "Your home directory is: $HOME"
Save with Ctrl + O, press Enter, then exit with Ctrl + X.
Make it executable and run it
Before running a script, you must give it execute permission:
chmod +x hello.sh
./hello.sh
Expected output:
Hello from Termux!
Today's date is: Mon Mar 17 10:32:14 UTC 2026
Your home directory is: /data/data/com.termux/files/home
Variables, Conditions, and Loops
Three concepts power almost every automation script: variables (storing data), conditions (making decisions), and loops (repeating actions). Here's a quick example that uses all three:
#!/data/data/com.termux/files/usr/bin/bash
# Variables
NAME="Termux User"
COUNT=5
# Condition
if [ "$NAME" != "" ]; then
echo "Hello, $NAME!"
fi
# Loop
for i in $(seq 1 $COUNT); do
echo "Task $i complete."
done
Variables are assigned without spaces around the = sign. Conditions use if [ ... ]; then ... fi syntax. Loops use for ... do ... done. These three building blocks are enough to write surprisingly powerful automation scripts for your Android device.
// 03 — Scheduling Tasks with Cron in Termux
Writing a script is only half of automation. The other half is making that script run automatically at the right time without you having to trigger it manually. That's where cron comes in. Cron is a time-based job scheduler built into Linux systems, and Termux supports it fully — no root required.
Starting the Cron Service
After installing cronie, you need to start the cron daemon:
crond
This starts the cron daemon in the background. To make it start automatically every time you open Termux, add it to your bash profile:
echo "crond" >> ~/.bashrc
Understanding Cron Syntax
Cron jobs are defined using a special 5-field time syntax. Each field represents a unit of time:
| Field | Values | Example |
|---|---|---|
| Minute | 0–59 | 30 = at minute 30 |
| Hour | 0–23 | 8 = at 8 AM |
| Day of Month | 1–31 | 1 = on the 1st |
| Month | 1–12 | * = every month |
| Day of Week | 0–6 (Sun=0) | 1 = Monday |
An asterisk * means "every". So * * * * * means "run every minute of every hour of every day." Here are some common examples:
# Every day at 8:00 AM
0 8 * * * /path/to/script.sh
# Every hour
0 * * * * /path/to/script.sh
# Every Monday at 9:30 AM
30 9 * * 1 /path/to/script.sh
# Every 5 minutes
*/5 * * * * /path/to/script.sh
Adding a Cron Job in Termux
Edit your crontab (the file where cron jobs are stored) with this command:
crontab -e
This opens the crontab file in a text editor. Add your cron job on a new line. For example, to run a script every day at 7 AM:
0 7 * * * /data/data/com.termux/files/home/myscript.sh
Save and exit. To verify your cron job was added correctly, list all active cron jobs:
crontab -l
/data/data/com.termux/files/home/) rather than relative paths. Cron runs in a minimal environment and may not recognize shortcuts.// 04 — Practical Automation Scripts You Can Use Today
Theory is useful, but practical examples are where things get exciting. Here are several real, ready-to-use bash automation scripts you can deploy in Termux right now. Each one solves a real problem and can be customized to your needs.
Script 1: Daily System Report
This script collects key information about your Termux environment and saves it to a log file automatically every morning:
#!/data/data/com.termux/files/usr/bin/bash
LOGFILE="$HOME/daily_report.txt"
DATE=$(date "+%Y-%m-%d %H:%M:%S")
echo "=============================" >> $LOGFILE
echo "Daily Report — $DATE" >> $LOGFILE
echo "=============================" >> $LOGFILE
echo "Uptime: $(uptime)" >> $LOGFILE
echo "Disk Usage:" >> $LOGFILE
df -h >> $LOGFILE
echo "Memory:" >> $LOGFILE
free -h >> $LOGFILE
echo "" >> $LOGFILE
echo "Report saved to $LOGFILE"
Schedule it daily at 6 AM by adding this to your crontab: 0 6 * * * ~/daily_report.sh
Script 2: Automatic File Backup
This script backs up a folder from your Android storage to a backup directory with a timestamp:
#!/data/data/com.termux/files/usr/bin/bash
SOURCE="$HOME/storage/shared/Documents"
DEST="$HOME/backups"
TIMESTAMP=$(date "+%Y%m%d_%H%M%S")
BACKUP_NAME="docs_backup_$TIMESTAMP"
mkdir -p "$DEST"
cp -r "$SOURCE" "$DEST/$BACKUP_NAME"
echo "Backup complete: $DEST/$BACKUP_NAME"
Script 3: Website Uptime Monitor
Check if a website is online and log the result. Useful for monitoring your own server or project:
#!/data/data/com.termux/files/usr/bin/bash
URL="https://example.com"
LOGFILE="$HOME/uptime_log.txt"
DATE=$(date "+%Y-%m-%d %H:%M:%S")
HTTP_CODE=$(curl -o /dev/null -s -w "%{http_code}" "$URL")
if [ "$HTTP_CODE" == "200" ]; then
echo "[$DATE] $URL — ONLINE (HTTP $HTTP_CODE)" >> $LOGFILE
else
echo "[$DATE] $URL — DOWN (HTTP $HTTP_CODE)" >> $LOGFILE
fi
Schedule this every 10 minutes with cron: */10 * * * * ~/uptime_monitor.sh
Script 4: Auto File Organizer
This script scans your Downloads folder and moves files into subfolders by file type automatically:
#!/data/data/com.termux/files/usr/bin/bash
DOWNLOADS="$HOME/storage/shared/Download"
mkdir -p "$DOWNLOADS/Images" "$DOWNLOADS/Videos" "$DOWNLOADS/Documents" "$DOWNLOADS/Archives"
for file in "$DOWNLOADS"/*; do
case "${file##*.}" in
jpg|jpeg|png|gif|webp) mv "$file" "$DOWNLOADS/Images/" ;;
mp4|mkv|avi|mov) mv "$file" "$DOWNLOADS/Videos/" ;;
pdf|docx|txt|xlsx) mv "$file" "$DOWNLOADS/Documents/" ;;
zip|tar|gz|rar) mv "$file" "$DOWNLOADS/Archives/" ;;
esac
done
echo "Downloads organized!"
.sh file, give it execute permission with chmod +x, then schedule it with cron.// 05 — Advanced Automation: APIs, Notifications, and More
Once you're comfortable with basic bash scripts and cron, you can take your Termux automation to the next level. Termux supports integrations with web APIs, push notifications, Python, and even Android system features through the Termux:API companion app. This section covers the most powerful advanced techniques.
Using Termux:API for Android Notifications
Termux:API is a companion app that bridges Termux scripts with Android system features like notifications, SMS, battery info, GPS, clipboard, and more. Install it from F-Droid, then install the API package inside Termux:
pkg install termux-api
Now you can send push notifications directly from your scripts:
termux-notification --title "Automation Complete" --content "Your backup script finished successfully!"
You can combine this with any of the scripts from the previous section. For example, add the notification command at the end of your backup script so you get a phone notification the moment the backup finishes.
Sending Telegram Messages from Termux
With a Telegram Bot and curl, you can send yourself messages from any Termux script. First, create a Telegram bot using BotFather and get your token and chat ID. Then use this function in your scripts:
#!/data/data/com.termux/files/usr/bin/bash
BOT_TOKEN="your_bot_token_here"
CHAT_ID="your_chat_id_here"
MESSAGE="Automation report: Backup complete at $(date)"
curl -s -X POST "https://api.telegram.org/bot$BOT_TOKEN/sendMessage" \
-d "chat_id=$CHAT_ID" \
-d "text=$MESSAGE" > /dev/null
echo "Telegram message sent."
Fetching Live Data from APIs
You can use curl and jq (a JSON parser) to pull live data from any public API. Install jq first:
pkg install jq
Then here's an example that fetches and displays the current weather for any city using the Open-Meteo API (free, no key required):
#!/data/data/com.termux/files/usr/bin/bash
# Coordinates for Bangalore, India
LAT="12.9716"
LON="77.5946"
RESULT=$(curl -s "https://api.open-meteo.com/v1/forecast?latitude=$LAT&longitude=$LON¤t_weather=true")
TEMP=$(echo "$RESULT" | jq '.current_weather.temperature')
WIND=$(echo "$RESULT" | jq '.current_weather.windspeed')
echo "Current Temperature: ${TEMP}°C"
echo "Wind Speed: ${WIND} km/h"
Running Python Alongside Bash
Bash and Python work seamlessly together in Termux. You can call Python scripts from bash, pass variables between them, and use Python's powerful libraries for tasks that are complex in pure bash. Install Python:
pkg install python
Then call a Python script from inside a bash automation script:
#!/data/data/com.termux/files/usr/bin/bash
echo "Running Python data processor..."
python3 ~/process_data.py
echo "Python script finished. Continuing bash automation..."
hydratermux.blogspot.com archive has dedicated guides on using Python in Termux, including how to set up pip and install third-party libraries. Check it out if you want to extend your automation scripts with Python packages.// Common Errors and Fixes
Error: Permission Denied
bash: ./myscript.sh: Permission denied
Fix: You forgot to make the script executable. Run:
chmod +x myscript.sh
Error: Bad Interpreter
/bin/bash: bad interpreter: No such file or directory
Fix: You're using the standard Linux shebang instead of the Termux one. Change the first line of your script from #!/bin/bash to:
#!/data/data/com.termux/files/usr/bin/bash
Cron Job Not Running
Fix: Check that the cron daemon is running with ps aux | grep crond. If it's not listed, start it manually with crond. Also make sure you're using the full absolute path to your script in the crontab, not a relative path.
Error: Command Not Found
command not found: jq
Fix: The package isn't installed. Use pkg install jq (or whatever the missing command is). If you're not sure of the package name, try pkg search keyword.
Script Exits Without Errors but Does Nothing
Fix: Add set -x at the top of your script to enable debug mode. Every command will be printed before it's executed, which makes it easy to spot where the script is going wrong.
#!/data/data/com.termux/files/usr/bin/bash
set -x # Enable debug mode
# Your script here
// Pro Tips for Termux Bash Automation
>> ~/logs/scriptname.log 2>&1. This captures both standard output and errors for troubleshooting later.set -e at the top of scripts you want to stop immediately if any command fails. This prevents scripts from continuing into a broken state.termux-wake-lock before starting long automation tasks to prevent this.git init ~/scripts and commit your scripts regularly so you can always roll back a bad change.// Comparison: Termux Automation vs Other Android Methods
| Method | Root Required | Programming | Power Level | Best For |
|---|---|---|---|---|
| Termux Bash | ❌ No | Bash / Python | ⭐⭐⭐⭐⭐ | Full automation, scripting, scheduling |
| Tasker (App) | ❌ No | Visual / KotlinScript | ⭐⭐⭐⭐ | Android UI triggers, GUI automation |
| IFTTT / Zapier | ❌ No | None (visual) | ⭐⭐ | Simple web-based triggers |
| Root Scripts | ✅ Yes | Bash / Any | ⭐⭐⭐⭐⭐ | Full system access, kernel control |
| MacroDroid | ❌ No | Visual | ⭐⭐⭐ | Simple trigger-action rules |
Termux clearly wins for power and flexibility among no-root options. It's the only method that gives you a full Linux scripting environment, access to thousands of packages, cron scheduling, and the ability to write genuinely complex multi-step automations.
// FAQ — Bash Automation in Termux
termux-wake-lock before setting up your cron jobs. You should also disable battery optimization for Termux in your Android settings (Settings → Apps → Termux → Battery → Unrestricted).~/.termux/boot/ directory. Scripts placed there will execute automatically each time your Android device boots.#!/data/data/com.termux/files/usr/bin/bash).crontab -e to open your crontab in the editor. Make your changes, then save and exit. The new cron schedule will take effect immediately. To remove all cron jobs, run crontab -r (be careful — this removes everything with no undo).// Conclusion — Start Automating Your Android Today
You've now learned everything you need to start building real, working bash automation scripts in Termux. From your first hello world script to scheduling cron jobs, sending Telegram notifications, fetching live API data, and organizing your files automatically — all of this is possible on your Android phone without root, without paid apps, and without any special hardware.
The key to getting good at automation is practice. Start small: pick one repetitive task you do every day and write a script for it this week. It doesn't have to be perfect. Once it works, improve it. Add logging. Add error handling. Add a notification. Before long, you'll have a collection of scripts quietly working for you in the background while you focus on things that actually need your attention.
Bash automation in Termux is a skill that compounds. Every script you write makes the next one easier. Every problem you debug teaches you something that applies to dozens of future scripts. It's one of the highest-leverage technical skills you can develop on an Android device.
If you found this guide helpful, explore more free tutorials at HYDRA TERMUX — new guides covering tools, scripting, and cybersecurity education are published regularly. Drop any questions you have in the comments below, and don't forget to share this post with anyone who wants to unlock the full power of their Android device. Start automating — your future self will thank you.

😍