How to Automate Tasks on Android Using Termux — Bash Automation Guide



Termux · Linux · Android Automation

How to Automate Tasks on Android Using Termux — Bash Automation Guide 2026

🆓 Free 🤖 No Root Required 📱 Android ✅ Tested 2026

// 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.

💡
Tip: Termux is available for free on F-Droid (recommended) or the Google Play Store. The F-Droid version is always more up to date.

// 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:

bash copy
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:

bash copy
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:

bash copy
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.

01

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.

⚠️
Warning: Always use the F-Droid version of Termux. The Google Play Store version is outdated and may have issues with package installations and cron scheduling.

// 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:

bash copy
#!/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

01

Create the script file

Use nano to create a new file called hello.sh:

bash copy
nano hello.sh
02

Type the script content

Inside nano, type the following:

bash copy
#!/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.

03

Make it executable and run it

Before running a script, you must give it execute permission:

bash copy
chmod +x hello.sh
./hello.sh

Expected output:

output copy
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
You just wrote and ran your first bash script in Termux. Every automation script you'll ever write follows exactly this same pattern.

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:

bash copy
#!/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:

bash copy
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:

bash copy
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
Minute0–5930 = at minute 30
Hour0–238 = at 8 AM
Day of Month1–311 = on the 1st
Month1–12* = every month
Day of Week0–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:

cron copy
# 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:

bash copy
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:

cron copy
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:

bash copy
crontab -l
💡
Tip: Always use absolute paths in cron jobs (the full path starting with /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:

bash copy
#!/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:

bash copy
#!/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:

bash copy
#!/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:

bash copy
#!/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!"
All four scripts above work on unrooted Android devices through Termux. Save each as a .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:

bash copy
pkg install termux-api

Now you can send push notifications directly from your scripts:

bash copy
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:

bash copy
#!/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:

bash copy
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):

bash copy
#!/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&current_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:

bash copy
pkg install python

Then call a Python script from inside a bash automation script:

bash copy
#!/data/data/com.termux/files/usr/bin/bash

echo "Running Python data processor..."
python3 ~/process_data.py

echo "Python script finished. Continuing bash automation..."
💡
Tip: The 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

output copy
bash: ./myscript.sh: Permission denied

Fix: You forgot to make the script executable. Run:

bash copy
chmod +x myscript.sh

Error: Bad Interpreter

output copy
/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:

bash copy
#!/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

output copy
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.

bash copy
#!/data/data/com.termux/files/usr/bin/bash
set -x  # Enable debug mode

# Your script here

// Pro Tips for Termux Bash Automation

💡
Tip 1 — Always log your output: Redirect script output to a log file using >> ~/logs/scriptname.log 2>&1. This captures both standard output and errors for troubleshooting later.
💡
Tip 2 — Use set -e: Add 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.
💡
Tip 3 — Keep Termux alive with wake lock: Android will kill background processes to save battery. Run termux-wake-lock before starting long automation tasks to prevent this.
💡
Tip 4 — Version control your scripts: Use git to keep track of changes to your automation scripts. Run git init ~/scripts and commit your scripts regularly so you can always roll back a bad change.
💡
Tip 5 — Use functions for repeated code: If you find yourself writing the same 5 lines in multiple scripts, define them as a function in a shared file and source it. This makes your scripts much easier to maintain.
💡
Tip 6 — Test before scheduling: Always run a new script manually several times before adding it to cron. Catch errors early, when you're watching the output in real time.

// 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

Do I need to root my Android device to automate tasks with Termux?
No, root is not required. Termux runs entirely in user space and provides a full bash scripting environment without any special system access. All the scripts and techniques in this guide work on completely stock, unrooted Android devices.
Will cron jobs keep running if I close the Termux app?
This depends on your Android settings. Android aggressively kills background processes to save battery. To keep cron running, acquire a wake lock using 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).
Can I run Termux automation scripts automatically on boot?
Yes. Install the Termux:Boot companion app from F-Droid, then place any script you want to run at startup inside the ~/.termux/boot/ directory. Scripts placed there will execute automatically each time your Android device boots.
What is the difference between bash and sh in Termux?
Bash (Bourne Again Shell) is a more feature-rich version of the original sh (Bourne Shell). In Termux, bash supports arrays, more advanced string operations, and additional syntax that sh doesn't. For automation scripts, always use bash (the shebang line for Termux is #!/data/data/com.termux/files/usr/bin/bash).
Can I schedule Termux scripts to send me WhatsApp messages?
Direct WhatsApp integration requires the WhatsApp Business API, which has limitations. A simpler and more reliable alternative is to use a Telegram bot (as shown in Section 5), which is free, has no rate limits for personal use, and works seamlessly with curl in Termux scripts.
How do I edit a cron job I already created?
Run 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.

Rixon Xavier

Founder — HYDRA TERMUX

Cybersecurity educator and Termux enthusiast. Creating free tutorials to help Android users learn Linux and ethical cybersecurity since 2023.

⚠️ Disclaimer: This tutorial is for educational purposes only. Always practice on systems you own or have explicit permission to test. HYDRA TERMUX does not support illegal activity of any kind.
``` --- ``` BLOGGER SETTINGS FOR THIS POST: Title: How to Automate Tasks on Android Using Termux — Bash Automation Guide 2026 Labels: termux, linux, android, Termux Tutorial, coding, terminal, No Root, android tools Search Description: Learn how to automate tasks on Android using Termux bash scripts and cron — no root required. Full guide with real scripts. (158 chars) Custom Robot Tags: all, noodp
Next Post Previous Post
1 Comments
  • Anonymous
    Anonymous March 17, 2026 at 11:44 PM

    😍

Add Comment
comment url