5 Python One-Liners That Automate Your Morning Routine (With Code)
I used to spend 20 minutes every morning doing the same boring tasks — checking file backups, organizing downloads, monitoring my server uptime, checking my revenue, and reading news. Then I realized all of it could be done in a single terminal command.
Here are 5 Python one-liners (one for each task) that now run automatically every morning. Each one is genuinely useful, not a toy example.
1. Find Files You Haven't Touched in 30 Days
Every morning, I run this to see which files in my Downloads folder are taking up space:
python3 -c "import os,time; [print(f'{os.path.getsize(p)//1024}KB {p}') for p in os.listdir('.') if os.path.isfile(p) and time.time()-os.path.getmtime(p)>2592000]"
What it does: Lists every file in the current directory that hasn't been modified in 30+ days, with file size. I pipe this to a cleanup checklist.
Why it matters: Digital hoarding slows your machine. This one-liner surfaces the dead weight so you can archive or delete it.
2. Check If Your APIs Are Still Alive
Before I start any work, I check that my critical services are up:
python3 -c "import urllib.request; [print(f'{u}: {\"UP\" if urllib.request.urlopen(u,timeout=5).status==200 else \"DOWN\"}') for u in ['https://google.com','https://github.com','https://api.gumroad.com']]"
What it does: Pings multiple URLs and prints "UP" or "DOWN" for each. I use this on a cron job to alert me if Gumroad or my VPS dashboard goes down.
Extend it: Replace the URLs with your own endpoints — Render, Railway, Fly.io, whatever you run.
3. Parse Your Server Logs for Errors
Instead of grepping manually, this one-liner summarizes errors by type:
python3 -c "import sys,re; from collections import Counter; c=Counter(re.findall(r'ERROR\s+(\w+)',sys.stdin.read())); [print(f'{k}: {v}') for k,v in c.most_common()]"
Usage: cat /var/log/nginx/error.log | python3 -c "..."
What it does: Reads log input, extracts error categories after "ERROR", and shows a ranked count. If your app logs ERROR DB_CONNECTION and ERROR AUTH_TIMEOUT, this tells you instantly which one is spiking.
4. Daily Revenue Snapshot
This is the one I actually look forward to. It reads a CSV from my revenue tracking and prints totals:
python3 -c "import csv,sys; rows=list(csv.DictReader(sys.stdin)); print(f'Today: {sum(float(r[\"amount\"]) for r in rows)}\nTotal sales: {len(rows)}')" < ~/income/revenue.csv
What it does: Takes a CSV with date,platform,amount,product_id columns, prints today's total and transaction count.
Pro tip: Replace CSV with your SQLite DB and it becomes even more powerful. I actually use sqlite3 for this now, but the CSV version is the one-liner I started with.
5. Generate a Morning Summary File
This one ties it all together. It writes a markdown summary of your morning check to a file:
python3 -c "from datetime import date; open(f'morning-{date.today()}.md','w').write(f'# Morning Briefing - {date.today()}\\n\\n## System\\n- Hostname: {__import__(\"socket\").gethostname()}\\n- Uptime: {open(\"/proc/uptime\").read().split()[0]}s\\n')"
What it does: Creates a dated markdown file with your hostname and system uptime. Not earth-shattering alone, but when combined with the other one-liners above (piped into the same file), you get a complete morning dashboard in 200ms.
How I Run All 5 in One Command
I have a single alias in my .bashrc:
alias morning='echo "=== STALE FILES ===" && python3 -c "..." && echo "=== API STATUS ===" && python3 -c "..." && echo "=== LOG ERRORS ===" && cat /var/log/nginx/error.log | python3 -c "..." && echo "=== REVENUE ===" && python3 -c "..."'
One command, 5 checks, done in 3 seconds.
The Principle Behind This
You don't need a dashboard app, a monitoring service, or a SaaS subscription for any of this. Python one-liners are the cheapest automation tool you already have. Every time you find yourself opening a browser tab to check something routine, ask: "Can I get this in a terminal command instead?"
Once you have it in a terminal command, you can put it in a cron job. Once it's in a cron job, you never think about it again.
If you want 20 more one-liners like this covering file management, data parsing, API monitoring, and automation — plus the scripts I use daily — check out my Python Utility Scripts Collection. It's the exact toolkit I built my morning routine from.
What's your favorite Python one-liner? Drop it in the comments — I'm always looking to add to my collection.
Top comments (0)