DEV Community

Stephano Kambeta
Stephano Kambeta

Posted on

Automate Tasks in Termux Using Bash Scripts

Let’s be honest—repeating the same Termux commands every day can get boring fast. What if you could automate all those boring steps and make your Android device work like a mini Linux machine? Good news: you can. And all you need is Bash scripting.

In this guide, I’ll show you how to write simple bash scripts in Termux to automate tasks, save time, and boost productivity. Whether you're scanning networks, launching tools, or creating backups, bash scripting has your back.

🧠 What Is a Bash Script?

A bash script is just a list of Linux commands written inside a text file. Instead of typing each command one by one, you run the script—and boom! It handles everything.

This is a powerful trick in Termux, especially if you’re into things like:

  • Automating scans with Nmap
  • Running phishing simulations like Zphisher
  • Launching Termux-based servers with Nginx

🛠️ How to Create a Bash Script in Termux

Let’s say we want to automate system updates. Here’s how to do it:

1. Open Termux and type:

nano update.sh
Enter fullscreen mode Exit fullscreen mode

2. Paste this content:

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

pkg update -y && pkg upgrade -y

Enter fullscreen mode Exit fullscreen mode

3. Save the file by pressing:

CTRL + X then Y then ENTER

4. Make it executable:

chmod +x update.sh
Enter fullscreen mode Exit fullscreen mode

5. Run the script:

./update.sh
Enter fullscreen mode Exit fullscreen mode

Simple, right? Now every time you want to update your system, just run the script.

🧩 Real-World Example: Automate a Network Scan

Here’s a script that runs a quick IP scan using Nmap:

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

echo "Enter target IP:"
read target
nmap -sP $target

Enter fullscreen mode Exit fullscreen mode

Save it as scan.sh, give it permission with chmod +x scan.sh, and run it.

For more advanced network tasks, check out this guide on Netcat in Termux.

🚀 Automate Ethical Hacking Tasks

If you're into cybersecurity, scripting becomes your best friend. Imagine launching a phishing tool like AnonPhisher or Weeman with one script.

Example:

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

cd $HOME/anonphisher
bash anonphisher.sh

Enter fullscreen mode Exit fullscreen mode

Running phishing tools? Learn how to protect yourself from phishing while testing ethically.

🔄 Schedule Scripts to Run Automatically

Want your script to run every time you open Termux?

Edit your .bashrc file:

nano ~/.bashrc
Enter fullscreen mode Exit fullscreen mode

Add this line at the end:

bash ~/update.sh
Enter fullscreen mode Exit fullscreen mode

Now, every time you launch Termux, your system updates automatically.

🔐 Security Tip

Automating tasks doesn’t mean ignoring security. While you work on Termux, don’t forget the big picture:

🔗 Related Reads from TerminalTools

Boost your Termux knowledge with these powerful guides:

Need more tools? Dive into:

✅ Final Words

Scripting in Termux turns you from a regular user into a power user. Once you get comfortable with bash, you’ll automate everything—from launching tools to running daily checks.

If you’re serious about becoming more efficient, start small. Write your first script today. And if you're just getting started with cybersecurity, explore our full guide on protecting your system.


💬 What task would you automate in Termux? Drop your ideas in the comments.

Top comments (0)