Your server drowning in temp files that nobody cleans? Same manual backup every day that you forget as soon as a client calls? Scheduling is a mix of attempts, ignored alarms, and forgetfulness? Good, you found the solution.
We, at Meteora Web, have built dozens of automations for Italian SMEs. We also come from accounting: we know that a missed backup costs more than a server. And that repeating operations like renaming reports, moving inventory files, or sending periodic emails by hand is time you could spend growing your business.
In this hands-on guide you'll see how to use Python — with the standard pathlib library and the system scheduler cron — to automate file management and recurring tasks. No external platforms, no monthly fees. Scripts you write once and run for years.
Why choose Python for automation in SMEs over other tools?
You could use Bash, PowerShell, or a no-code tool like Make. But Python has three concrete advantages for an SME:
- Readability: a Python script can be understood even by a colleague who isn't a professional developer. You modify it without fear.
- Portability: same script on Linux, Windows, macOS. With pathlib you don't worry about slashes and backslashes.
- Ecosystem: if tomorrow the automation needs to send an email, connect to an API, or read a database, Python has the library ready.
We used Python to automate daily sales report downloads from an ERP, rename them with the date, and upload them to a NAS. An e-commerce client had images weighing several MB: with a Python script and pathlib we reduced weight by 60% without quality loss, scheduling processing overnight.
Sponsored Protocol
The right question isn't “does it work?” but “how much does it cost me not to do it?”
What makes pathlib the best choice for file management?
For years Python developers used os.path with hand-written strings and backslashes. Result: fragile code, errors on Windows, hardcoded paths. Pathlib (introduced in Python 3.4) changes everything: every path is an object with intuitive methods and safe operations.
Essential pathlib operations
Here are the commands you'll use in 90% of automations:
from pathlib import Path
# Base path
base = Path("/var/log/my_client")
# List only .log files
log_files = list(base.glob("*.log"))
# Read content (with safe encoding)
for file in log_files:
text = file.read_text(encoding="utf-8")
if "ERROR" in text:
print(f"Found error in {file.name}")
# Create directory if not exists
backup_dir = base / "backup"
backup_dir.mkdir(parents=True, exist_ok=True)
# Copy file (pathlib has no built-in copy, use shutil)
import shutil
shutil.copy2(file, backup_dir / file.name)
# Delete files older than 7 days
import time
threshold = time.time() - 7 * 86400
for file in backup_dir.iterdir():
if file.is_file() and file.stat().st_mtime < threshold:
file.unlink()Common mistake: using os.listdir() and building paths manually. With pathlib you don't need to: Path.iterdir() gives you Path objects directly.
Sponsored Protocol
When a server's SSL certificate auto-renewal broke, we wrote a script with pathlib that checked the expiry of .pem files and, if fewer than 30 days remained, launched certbot. Scheduled with cron, it fixed the problem without taking the client offline.
How to schedule Python scripts with Cron on Linux?
Cron is the historic Unix scheduler. It works with a configuration file (crontab) where each line specifies minute, hour, day, month, day of week, and command. Perfect for Python scripts.
Crontab line structure
# Minute Hour Day Month DayWeek Command
30 2 * * * /usr/bin/python3 /home/meteora/script/backup.pyThe five fields read: “run every day at 2:30”. You can use asterisks (all), ranges (1-5), steps (*/15 every 15 minutes), and lists (1,15).
Sponsored Protocol
Practical crontab commands
crontab -e— edit the current user's crontabcrontab -l— list active jobscrontab -r— remove all jobs (careful!)
Golden rule: use absolute paths for both the Python interpreter and the script. Cron does not have the same PATH as your shell.
# WRONG (won't find python)
0 9 * * * python script.py
# CORRECT
0 9 * * * /usr/bin/python3 /home/meteora/script/daily_report.pyReal example: nightly inventory file backup
A client of ours runs a clothing store with CSV inventory files. They wanted an automatic copy every night.
Python script:
from pathlib import Path
import shutil
from datetime import datetime
source = Path("/var/data/inventory")
destination = Path("/mnt/nas/backup_inventory")
today = datetime.now().strftime("%Y-%m-%d")
dest_today = destination / today
dest_today.mkdir(parents=True, exist_ok=True)
for file in source.glob("*.csv"):
shutil.copy2(file, dest_today / file.name)
print(f"Backup of {len(list(source.glob('*.csv')))} files completed.")Then we added to the user's crontab:
Sponsored Protocol
0 3 * * * /usr/bin/python3 /home/meteora/backup_inventory.py >> /var/log/backup_inventory.log 2>&1The redirect >> /var/log/... 2>&1 saves output and errors to a file. If something goes wrong, you see it in the log.
What common mistakes to avoid when combining pathlib and cron?
We've seen dozens of “almost working” scripts. Here are the most frequent issues:
- Relative path in the script: Cron runs from the user's home directory, not the script's folder. Solution: use
Path(__file__).resolve().parentto get the script's directory. - Missing environment variables: If the script uses variables (e.g., DB password), load them inside or use a .env file. Don't assume cron inherits them.
- Insufficient permissions: The script run by cron may not have access to system folders. Test manually with the same user as the crontab.
- No logging: A silent script is a time bomb. Always write output to a file with timestamps.
# Minimal logging example
import logging
logging.basicConfig(filename="/var/log/automation.log", level=logging.INFO,
format='%(asctime)s %(message)s')
logging.info("Script started")
# ...
logging.info("Script completed successfully")Firm stance: Security in SMEs is systematically undervalued. If the script touches sensitive data, use config files with permissions 600 and never hard-code credentials.
Sponsored Protocol
What to do now — implement your first automation in 30 minutes
Don't just read. Put into practice right now:
- Identify a repetitive task: what do you do manually every day? Renaming files, moving downloads, cleaning temp files?
- Write a Python script with pathlib that performs that task. Use
Path.glob(),shutil.copy2(),Path.unlink(). - Add logging: even just a line to a file with the date and number of processed files.
- Test manually: run the script from the shell with the user that will own the crontab.
- Schedule with cron:
crontab -eand add the line with absolute paths and log redirection. - Check the log the next day: open the log file and verify everything went fine.
We, at Meteora Web, do this every day for our clients. If you need a hand setting up your first script or evaluating the economic return of automation, start from our pillar guide on Python for Developers and get in touch.
A website is measured in revenue, not compliments. An automation is measured in hours recovered.