Automate the Boring Stuff in Your Server With Scripts and Bots
Every developer has tasks they do repeatedly. Restarting a service after a crash. Cleaning up old log files. Sending a daily summary to a Discord channel. Checking if a website is still up. Backing up a database.
These tasks are boring, repetitive, and easy to forget. They're also perfect candidates for automation.
The best developers aren't the ones who work the hardest — they're the ones who make the computer work hard for them. Let's talk about what you should be automating and how to actually do it.
The Automation Mindset
There's a simple rule:
If you've done it three times, automate it.
Not everything is worth automating. Writing a complex script for something you do once a year is overkill. But if you find yourself repeating the same steps every day, every week, or every time something happens — that's a script waiting to be written.
Signs You Should Automate
- You're doing the same terminal commands in the same order regularly
- You forget to do a recurring task and something breaks
- A task involves checking something and then doing something based on the result
- You're copying data between systems manually
- Someone asks you "can you do X" and it's always the same X
Server Automation: The Low-Hanging Fruit
Auto-Restart on Crash
Services crash. It happens. The question is whether they come back automatically or wait for you to notice.
A simple process manager handles this:
# Using a basic restart loop
while true; do
node app.js
echo "Process crashed. Restarting in 5 seconds..."
sleep 5
done
But for proper production use, tools like PM2 (Node.js), supervisord (any process), or systemd services handle restarts, logging, and resource limits properly.
Log Rotation and Cleanup
Log files grow forever if you let them. Eventually they fill your disk and everything breaks.
#!/bin/bash
# Clean logs older than 7 days
find /var/log/myapp -name "*.log" -mtime +7 -delete
echo "$(date): Cleaned old logs" >> /var/log/cleanup.log
Schedule it with cron and never think about it again:
0 3 * * * /home/user/scripts/clean-logs.sh
Automated Backups
If your data matters, back it up. If you're backing it up manually, you're going to forget.
#!/bin/bash
TIMESTAMP=$(date +%Y%m%d_%H%M%S)
BACKUP_DIR="/backups"
# Database backup
pg_dump mydb > "$BACKUP_DIR/db_$TIMESTAMP.sql"
# Keep only last 7 days
find "$BACKUP_DIR" -name "*.sql" -mtime +7 -delete
Health Checks
A script that checks if your services are healthy and notifies you if they're not:
import requests
import os
services = [
{"name": "Website", "url": "https://example.com", "expected": 200},
{"name": "API", "url": "https://api.example.com/health", "expected": 200},
]
for service in services:
try:
response = requests.get(service["url"], timeout=10)
if response.status_code != service["expected"]:
notify(f"{service['name']} returned {response.status_code}")
except requests.exceptions.RequestException as e:
notify(f"{service['name']} is unreachable: {e}")
Bot Automation: Making Communities Run Themselves
Discord Bots as Automation Engines
Discord bots aren't just for fun commands. They're powerful automation tools for community management:
Automated Welcome Flows
Instead of manually greeting every new member:
@bot.event
async def on_member_join(member):
# Send welcome DM with server rules
await member.send(f"Welcome to {member.guild.name}! Please read #rules.")
# Assign default role
role = discord.utils.get(member.guild.roles, name="New Member")
if role:
await member.add_roles(role)
# Log to mod channel
log_channel = discord.utils.get(member.guild.channels, name="mod-log")
if log_channel:
await log_channel.send(f"New member: {member.mention} (Account age: {member.created_at})")
Scheduled Announcements
Post recurring messages without remembering to do it:
from discord.ext import tasks
@tasks.loop(hours=168) # Weekly
async def weekly_thread():
channel = bot.get_channel(CHANNEL_ID)
thread = await channel.create_thread(
name=f"Weekly Discussion - {datetime.now().strftime('%B %d')}",
auto_archive_duration=10080
)
await thread.send("What's everyone working on this week?")
Auto-Moderation
Handle common moderation tasks automatically:
@bot.event
async def on_message(message):
if message.author.bot:
return
# Auto-delete messages with too many mentions
if len(message.mentions) > 5:
await message.delete()
await message.channel.send(
f"{message.author.mention}, mass mentions aren't allowed.",
delete_after=10
)
Beyond Discord
The same automation principles apply everywhere:
- Telegram bots for personal notifications and reminders
- Slack bots for team workflow automation
- GitHub Actions for repository management
- Webhooks for connecting services together
Workflow Automation: Connecting the Dots
Webhook Chains
Modern services support webhooks — HTTP callbacks that fire when something happens. Chain them together:
- GitHub push triggers a webhook
- Your server receives it and runs a deploy script
- Deploy script pulls code, restarts service
- Health check verifies the deployment
- Discord bot posts a success/failure message
That entire pipeline runs without human intervention.
Cron Jobs: The Unsung Hero
Cron is decades old and still one of the most powerful automation tools:
# Every day at midnight: backup database
0 0 * * * /scripts/backup.sh
# Every hour: check service health
0 * * * * /scripts/health-check.sh
# Every Monday at 9 AM: generate weekly report
0 9 * * 1 /scripts/weekly-report.sh
# Every 5 minutes: check disk space
*/5 * * * * /scripts/disk-check.sh
Simple, reliable, battle-tested.
File Watchers
React to file changes in real-time:
from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler
class DeployHandler(FileSystemEventHandler):
def on_modified(self, event):
if event.src_path.endswith('.env'):
restart_service()
elif event.src_path.endswith('.json'):
reload_config()
observer = Observer()
observer.schedule(DeployHandler(), path='/app/config', recursive=False)
observer.start()
Building Your Automation Stack
Start Small
Don't try to automate everything at once. Pick the one task that annoys you most and automate that first.
Good first automations:
- Auto-restart for your most important service
- Daily backup of your database or important files
- Discord notification when something goes wrong
- Log cleanup so your disk doesn't fill up
Make It Reliable
Automation that fails silently is worse than no automation. Every automated task should:
- Log what it does — so you can audit later
- Notify on failure — so you know when it breaks
- Handle edge cases — what if the service is already down? What if the disk is full?
- Be idempotent — running it twice shouldn't cause problems
Document It
Future-you will forget why you wrote that cron job. Add a comment:
#!/bin/bash
# clean-old-sessions.sh
# Removes session files older than 24 hours
# Runs daily via cron at 2 AM
# Without this, the sessions directory grows ~500MB/week
find /tmp/sessions -mtime +1 -delete
Monitor Your Automation
Automated tasks need monitoring too. If your backup script fails silently for two weeks, you don't have backups.
Set up alerts for:
- Backup scripts that haven't run recently
- Health checks that stopped reporting
- Disk space that's growing despite cleanup
- Services that keep restarting (crash loops)
The Payoff
Once you build the habit of automating, you start seeing opportunities everywhere:
- A five-minute daily task becomes a one-time afternoon of scripting
- A task you forget once a month becomes something that just happens
- Communication that requires you to remember becomes automatic notifications
- Recovery from failures goes from "twenty minutes of panicking" to "it already restarted itself"
Think about where your time goes each week. How much of it is spent on tasks a script could handle? Even reclaiming a few hours a week adds up to days over a year.
The One Rule
If there's one takeaway, it's this:
Your time should be spent on problems that require human judgment. Everything else should be automated.
You're a developer. The computer should be doing the repetitive work — not you.
— The Bytevora Team

