← All articles
Python Automation and Bash Commands: Practical Scripts That Save Hours Every Week
Python automation

Python Automation and Bash Commands: Practical Scripts That Save Hours Every Week

By John Simiyu · 30 November 2026 · 9 min read

About the author

John Simiyu, known as Simiyu the Software Developer, is an experienced full-time full-stack software developer with proven, robust skills in web development using PHP, Bootstrap, JavaScript, HTML, MySQL and CSS, Python for automation, and Kotlin and Java for native Android development. He has over 5 years of experience building websites, business systems and mobile apps for clients. He also runs Scolemax Solutions, a Kenyan hosting business, which is mentioned in this article.

Stop doing the same task twice

Think about your week. How many tasks do you repeat? Renaming files, copying figures from one spreadsheet to another, backing up a website, cleaning a list of customers, checking if a site is still online.

Every repeated task is a candidate for automation. You write a small script once, and the computer does the work from then on, without getting bored or making typing mistakes.

Two tools make this practical for almost anyone: Python, which is great for working with files, spreadsheets and data, and bash, the command line on Linux servers, which is great for running programs, moving files and scheduling jobs. In this article I show you real examples of both, and how to make them run by themselves.

Why Python and bash together

  • - Python is easy to read and has libraries for Excel, email, web requests and much more
  • Bash is already on almost every Linux server, with nothing to install
  • Python does the thinking, while bash handles running and scheduling it
  • Both are free and work on Windows, Mac and Linux, with Windows users able to use Python directly or a Linux environment for bash

Bash commands you will use all the time

If you work on a server or a VPS, you will use these every day:

  • - pwd shows the folder you are in
  • ls lists files, and ls -la shows details and hidden files
  • cd foldername moves into a folder, and cd .. goes back up
  • mkdir foldername creates a folder
  • cp file1 file2 copies a file
  • mv file1 file2 moves or renames a file
  • cat file.txt prints a file's contents
  • tail -n 50 file.log shows the last 50 lines of a file, and tail -f file.log keeps showing new lines as they appear
  • grep "error" file.log finds lines containing a word
  • chmod +x script.sh makes a script runnable
  • nano file.txt opens a simple text editor
  • df -h shows disk space and free -h shows memory

A safety warning: be careful with rm, which deletes files with no recycle bin. Never run a command that contains rm -rf unless you are completely sure what path it points to. When testing, use ls first to see what a command would affect.

Script 1: Tidy a messy folder with Python

Does your Downloads folder look like a market on Saturday? This script sorts files into folders by type.

Create a file called tidy.py:

PYTHON
from pathlib import Path
import shutil

folder = Path("Downloads")

groups = {
    "Images": [".jpg", ".jpeg", ".png"],
    "Documents": [".pdf", ".docx", ".xlsx", ".txt"],
    "Archives": [".zip", ".rar"],
}

for item in folder.iterdir():
    if not item.is_file():
        continue
    for name, extensions in groups.items():
        if item.suffix.lower() in extensions:
            target_folder = folder / name
            target_folder.mkdir(exist_ok=True)
            target = target_folder / item.name
            if not target.exists():
                shutil.move(str(item), str(target))
            break

Run it with: python3 tidy.py

How it works: it looks at every file, checks the file extension, creates a folder if needed and moves the file there. It skips a file if one with the same name already exists, so nothing is overwritten. Change the folder name and the extensions to fit your own needs.

Script 2: Turn a messy Excel sheet into a clean report

Many businesses record sales in Excel, and someone spends hours every month summarising it. Python can do this in seconds.

First, install the libraries:

pip install pandas openpyxl

Imagine a file called sales.xlsx with the columns Date, Product and Amount. Create report.py:

PYTHON
import pandas as pd

df = pd.read_excel("sales.xlsx")

# Clean the data
df["Date"] = pd.to_datetime(df["Date"], errors="coerce")
df["Amount"] = pd.to_numeric(df["Amount"], errors="coerce")
df = df.dropna(subset=["Date", "Amount"])
df["Product"] = df["Product"].str.strip().str.title()

# Summarise by product
summary = (
    df.groupby("Product")["Amount"]
    .agg(["count", "sum"])
    .sort_values("sum", ascending=False)
)

summary.to_excel("sales_report.xlsx")
print(summary)

What it does:

  • - Reads your spreadsheet
  • Fixes dates and numbers, and drops rows that are missing important values
  • Cleans product names, so " milk" and "Milk" are counted together
  • Groups the sales by product, showing how many sales and the total value
  • Saves a clean report as a new Excel file

You can adapt it for monthly totals, customer lists, stock counts or expense summaries. Always check the cleaned result against the original once, so you trust what the script is doing.

Script 3: Back up your website with bash

A backup you forget to make is a backup you do not have. This bash script compresses your website files into a dated archive and deletes backups older than seven days.

Create a file called backup.sh:

BASH
#!/bin/bash

BACKUP_DIR="$HOME/backups"
SITE_DIR="$HOME/public_html"
DATE=$(date +%F)

mkdir -p "$BACKUP_DIR"

tar -czf "$BACKUP_DIR/site-$DATE.tar.gz" "$SITE_DIR"

find "$BACKUP_DIR" -name "site-*.tar.gz" -mtime +7 -delete

echo "Backup finished: $DATE"

Then make it runnable and test it:

chmod +x backup.sh
./backup.sh

Adjust SITE_DIR to the folder where your website files live. To back up a MySQL database as well, you can add a mysqldump line. Store the database password in a protected option file instead of typing it into the script, and keep the file readable only by you.

Make it run by itself with cron

A script is helpful. A script that runs on its own is automation. On Linux, cron is the scheduler that does this.

Open your schedule with:

crontab -e

Then add a line such as:

0 2 * * * /home/youruser/backup.sh >> /home/youruser/backup.log 2>&1

The five fields at the start mean minute, hour, day of the month, month and day of the week. So 0 2 * means "at 2:00 AM every day". The end of the line saves the script's output to a log file, so you can check later what happened.

You can schedule Python scripts the same way:

30 7 * * 1 python3 /home/youruser/report.py

That runs the report script at 7:30 every Monday morning. Use full paths in cron, because it does not run in the same environment as your normal terminal.

Where to run your scripts

Scripts on your own laptop only run when the laptop is on and connected. For things that must run every night, such as backups, reports or checks, it is better to run them on a server that stays online.

I run Scolemax Solutions, so here is how its plans fit, based on what the Scolemax website lists today:

  • - Dev Containers come with languages such as Python (including Django and FastAPI stacks) already set up, so you can start running scripts quickly. The entry plan is small so it suits learning and light scheduled scripts, not heavy data processing.
  • Ryzen KVM servers, from KES 1,050 per month, are aimed at demanding workloads, bots and scripts, and give you full control of the machine.
  • KVM Rootservers, from KES 980 per month, suit business workloads where you want your own server.

Please confirm current plans and prices on scolemax.com before you buy, since they can change. Whatever host you choose, remember that on a server you manage yourself, you are responsible for security, updates and backups.

Ideas for automating your business

Once you have run these examples, you will start seeing other tasks to automate:

  • - Sending the same report to a manager every week
  • Cleaning customer lists and removing duplicates
  • Renaming and organising scanned documents
  • Checking whether your website is online and alerting you if it is not
  • Generating invoices or statements from a spreadsheet
  • Pulling data from a database into a daily summary
  • Sending reminders, only to people who have agreed to receive them

If you do something repetitive on a computer at least once a week, there is a good chance it can be automated.

Safety habits for automation

  • - Test every script on copies of your files, not on the only copy
  • Be careful with any command that deletes files, and print what you are about to delete first
  • Keep passwords and keys out of your scripts and use protected configuration files
  • Log what your scripts do so that you can see what happened
  • Do not send automated messages to people who have not agreed to receive them
  • Respect the terms of any website or service you connect your scripts to
  • Review scheduled jobs from time to time and remove the ones you no longer need

Common mistakes to avoid

  • - Running a new script on your only copy of important data
  • Using rm -rf without double-checking the path
  • Using relative paths in cron, so the script cannot find its files
  • Forgetting chmod +x on a bash script
  • Not logging, so you cannot tell why a job failed
  • Hard-coding passwords inside scripts
  • Automating a messy process before understanding it

Bonus points before you go

  • - Bonus 1: Write down the tasks you repeat this week. The one that annoys you most is your first automation project.
  • Bonus 2: Start tiny. A ten-line script that saves five minutes a day adds up to hours across a year.
  • Bonus 3: Read your scripts out loud in plain English. If you cannot say what a line does, do not run it on important data.
  • Bonus 4: Check your logs after the first few runs. Most automation problems show up early.
  • Bonus 5: A backup you have never tested is only a hope. Restore one to a test folder to be sure it works.

Final thoughts

Python and bash are not only for professional developers. With a few small scripts, a business owner, a student or a freelancer can reclaim hours every week and make fewer mistakes. Start with one task, test it carefully and schedule it once you trust it.

If you want custom automation for your business, such as report generation, data cleaning, backups or scheduled tasks, I would be glad to help. You can explore server plans at https://scolemax.com. Contact me on WhatsApp at 0739334082 or email consult@johnsimiyuweb.site.

Next, read: Basic Linux Commands Every Web Developer Should Know

Want to learn PHP & MySQL live with me? Book the training →

Comments (0)

No comments yet. Be the first to share your thoughts.

Leave a comment

Comments are reviewed before they appear. Links are not allowed.

Keep reading