Author Archives: admin@111247

Automating File Cleanup and Cron Jobs on Linux: A Complete Step-by-Step Guide


Web applications regularly generate temporary files, logs, and session data. Over time, these files accumulate and can overwhelm the server, causing:

  • Slower performance
  • Application errors
  • Disk exhaustion
  • Unexpected crashes

To maintain a healthy server environment, it’s essential to automate tasks such as deleting old files, running scheduled cleanup jobs, and executing routine maintenance commands.
This guide provides a complete walkthrough of identifying file locations, setting up automated cleanup using systemd timers, and scheduling URL or command-based tasks using cron jobs.


📂 1. Identify the Directory That Needs Automatic Cleanup

Most PHP-based or custom applications generate session files in paths similar to:

/path/to/project/src/var/sessions

First, verify the directory exists:

ls -l /path/to/project/src/var/sessions

If you see files like:

sess_abcd1234
sess_xyz890

—then this is the correct directory to clean.


🧪 2. Test File Removal (Without Deleting Anything Yet)

Before deleting files, list which files would be removed.
To list files older than 20 hours:

find /path/to/project/src/var/sessions -type f -mmin +1200 -print

This safely shows all files older than 20 hours without removing them.

Use this list to confirm you’re targeting the correct directory.


🗑️ 3. Create a Systemd Service to Delete Old Files Automatically

Systemd services allow you to automate tasks in a robust and secure way.

Create the service file:

sudo nano /etc/systemd/system/session-cleaner.service

Paste the following:

[Unit]
Description=Automatically delete old session/log files

[Service]
Type=oneshot
ExecStart=/usr/bin/find /path/to/project/src/var/sessions -type f -mmin +1200 -delete

Explanation:

  • -mmin +1200 → delete files older than 20 hours
  • Adjust to:
    • 1 day: +1440
    • 2 days: +2880

Save and exit.


⏲️ 4. Create a Systemd Timer to Run Cleanup on a Schedule

Now create the timer that will run this service automatically:

sudo nano /etc/systemd/system/session-cleaner.timer

Paste:

[Unit]
Description=Run session cleaner at regular intervals

[Timer]
OnBootSec=30min
OnUnitActiveSec=12h
Unit=session-cleaner.service

[Install]
WantedBy=timers.target

This will:

  • Run 30 minutes after boot
  • Then run every 12 hours

Activate the timer:

sudo systemctl daemon-reload
sudo systemctl enable --now session-cleaner.timer

Verify:

systemctl status session-cleaner.timer

🧹 5. Test the Cleanup Service Manually

Before relying on the timer, test the service once:

sudo systemctl start session-cleaner.service

Verify cleanup:

ls -l /path/to/project/src/var/sessions

Old files will be removed.


🔄 6. Adding a Cron Job to Run a URL or Script Automatically

Many web applications require scheduled tasks such as:

  • Running background processing
  • Triggering API calls
  • Executing maintenance scripts

If your application exposes a task runner as a URL, for example:

https://yourdomain.com/runtasks?token=YOUR_TOKEN_HERE

You can run it using a cron job.

Open crontab:

crontab -e

Add this entry to run every 15 minutes:

*/15 * * * * /usr/bin/wget -q -O /dev/null "https://yourdomain.com/runtasks?token=YOUR_TOKEN_HERE"

✔ What this does:

  • Runs every 15 minutes
  • Silences output (-q)
  • Prevents log files (-O /dev/null)
  • Safely executes the task URL

✔ Recommended for environments like CloudPanel

Run cron under the website’s user:

sudo -u youruser crontab -e

Paste the same cron entry.


7. Systemd Timer vs Cron Jobs — Which Should You Use?

FeatureCronSystemd Timer
PrecisionModerateVery accurate
Run on bootNoYes
LoggingMinimalDetailed
ReliabilityGoodExcellent
Best useURL triggers, simple tasksFile cleanup, maintenance tasks

Use systemd timers for cleanup tasks.
Use cron jobs for URL-based or script-based automation.


🔐 8. Protecting Sensitive Information in Automation

When automating tasks, always protect:

  • API keys
  • Tokens in URLs
  • Database credentials
  • Access scripts
  • Config files

Recommended Practices:

✔ Use HTTPS for all task URLs
✔ Keep tokens long, random, and confidential
✔ Avoid output logs using -q -O /dev/null
✔ Restrict access to systemd and cron files
✔ Make sure only the application user can access sensitive directories


🎉 Conclusion

Automating file cleanup and task scheduling is essential for maintaining a healthy, stable, and secure web server. By properly configuring systemd services, systemd timers, and cron jobs, you ensure:

  • Clean session and log directories
  • Optimal disk usage
  • Reliable recurring tasks
  • Reduced risk of server slowdowns or crashes

This guide gives you everything you need to implement a production-ready, automated maintenance system on any Linux or CloudPanel-based server.

21 Raspberry Pi Projects You Can Build: A Complete Guide

The Raspberry Pi has transformed DIY electronics, computing education, and home automation by providing a powerful yet affordable single-board computer. From building retro gaming consoles to creating AI-powered smart assistants, the Raspberry Pi’s versatility opens the door to hundreds of exciting project possibilities.

Whether you’re a beginner exploring your first build or an experienced maker looking for inspiration, this guide details 21 Raspberry Pi projects, complete with materials, instructions, and explanations of how each one works.

Let’s dive into the world of Raspberry Pi creativity.


1. Raspberry Pi Retro Gaming Console (RetroPie or RecalBox)

Description

Turn your Raspberry Pi into a fully functional retro gaming console that can emulate NES, SNES, PlayStation, Sega, Atari, and more.

Materials

  • Raspberry Pi 3/4
  • MicroSD card (32GB or higher)
  • HDMI cable
  • USB/Bluetooth game controllers
  • RetroPie or RecalBox OS image

Steps

  1. Download the RetroPie image.
  2. Flash it onto the SD card using Raspberry Pi Imager or BalenaEtcher.
  3. Boot the Pi and configure the controller.
  4. Add ROMs via USB or network share.
  5. Select and play games from the EmulationStation menu.

2. Raspberry Pi Home Media Server (Plex or Jellyfin)

Description

Stream movies, TV shows, and music on all your devices.

Materials

  • Raspberry Pi 4 with 4GB–8GB RAM
  • USB external storage
  • Plex or Jellyfin software

Steps

  1. Install Raspberry Pi OS.
  2. Install Plex Media Server: sudo apt install plexmediaserver
  3. Add media folders.
  4. Access Plex through a browser and configure libraries.
  5. Stream to Smart TVs, phones, and PCs.

3. Smart Home Hub (Home Assistant)

Description

Control your home automation devices from a unified dashboard.

Materials

  • Raspberry Pi 4
  • Home Assistant OS
  • Zigbee/Z-Wave USB dongle (optional)

Steps

  1. Download Home Assistant OS and flash it.
  2. Access the web UI through http://homeassistant.local.
  3. Add integrations (lights, plugs, sensors).
  4. Create automations like:
    • Turn lights on at sunset
    • Temperature-based climate control

4. Network-Wide Ad Blocker (Pi-hole)

Description

Pi-hole blocks ads across your entire home network.

Materials

  • Raspberry Pi (any model)
  • Raspberry Pi OS Lite

Steps

  1. Install Pi-hole: curl -sSL https://install.pi-hole.net | bash
  2. Configure your router to use Pi-hole as DNS.
  3. Access the web dashboard.
  4. Monitor blocked domains and analytics.

5. Personal Cloud Storage (Nextcloud)

Description

Host your own Dropbox/Google Drive alternative.

Materials

  • Raspberry Pi 4
  • External HDD/SSD
  • NextcloudPi image

Steps

  1. Flash NextcloudPi.
  2. Complete the wizard through the web interface.
  3. Create users and upload files.
  4. Access files from desktop or mobile apps.

6. Weather Station with Environmental Sensors

Description

Collect real-time temperature, humidity, air pressure, and AQI.

Materials

  • Raspberry Pi (any)
  • DHT22 or BME280 sensor
  • Jumper wires

Steps

  1. Connect the sensor to GPIO pins.
  2. Install required Python libraries.
  3. Write a script to read sensor data.
  4. Display values on a web dashboard (Flask or Node-RED).

7. Smart Mirror (MagicMirror²)

Description

Create a futuristic mirror with widgets for time, weather, calendar, and news.

Materials

  • Raspberry Pi 3/4
  • Monitor
  • Two-way acrylic mirror
  • MagicMirror² software

Steps

  1. Install MagicMirror² via: curl -sL https://install.magicmirror.builders | bash
  2. Build the mirror frame.
  3. Place the monitor behind the two-way mirror.
  4. Configure modules such as weather, clock, and RSS.

8. Security Camera System

Description

Use the Pi as a surveillance system with motion detection and cloud backups.

Materials

  • Raspberry Pi
  • Pi Camera Module
  • MotionEyeOS or Motion

Steps

  1. Install MotionEyeOS.
  2. Configure camera settings (FPS, resolution).
  3. Set notifications for motion detection.
  4. View live feeds on any device.

9. Portable Hacking Tool (Kali Linux Pi)

Description

Set up a cybersecurity testing toolkit using Kali Linux.

Materials

  • Raspberry Pi 4
  • Kali Linux ARM image
  • Portable power bank

Steps

  1. Flash Kali Linux.
  2. Install tools like Nmap, Wireshark, Metasploit.
  3. Use Pi as a portable penetration testing device (ethical use only).

10. AI Voice Assistant (Mycroft or Rhasspy)

Description

Build your own voice assistant alternative to Alexa or Siri.

Materials

  • Raspberry Pi 4
  • USB microphone
  • Speaker
  • Mycroft/Rhasspy software

Steps

  1. Install Mycroft (“Picroft”).
  2. Configure microphone and speaker.
  3. Train wake-word detection.
  4. Add skills like:
    • Weather information
    • Music playback
    • Home automation control

11. Robot Car with Motor Control

Description

Build a mobile robot controlled via WiFi or Bluetooth.

Materials

  • Raspberry Pi Zero/3/4
  • Motor driver board (L298N)
  • DC motors
  • Car chassis

Steps

  1. Assemble the robot chassis.
  2. Connect motors to L298N and Pi GPIO.
  3. Write Python code to control direction.
  4. Add camera streaming for FPV.

12. Smart Doorbell with Face Recognition

Description

A doorbell that uses the Pi Camera and a face-recognition library.

Materials

  • Raspberry Pi 4
  • Pi Camera
  • Push button
  • OpenCV, face_recognition library

Steps

  1. Connect the button to GPIO.
  2. Capture an image when the button is pressed.
  3. Run face recognition to identify known visitors.
  4. Send alerts via email or Telegram.

13. Time-Lapse Camera

Description

Automate taking photos at set intervals for time-lapse videos.

Materials

  • Raspberry Pi Zero/4
  • Pi Camera
  • Python script

Steps

  1. Install picamera or libcamera.
  2. Schedule periodic captures using cron.
  3. Use FFmpeg to turn images into a video.

14. Pi-Powered Digital Photo Frame

Description

Display rotating images from USB, network, or cloud.

Materials

  • Raspberry Pi
  • Monitor or digital frame
  • Python or slideshow software

Steps

  1. Create a photo playlist.
  2. Use a script to cycle images.
  3. Add transition effects and schedule updates.

15. LED Matrix Display Board

Description

Show scrolling text, animations, or sensor data.

Materials

  • Raspberry Pi
  • 8×8 or 32×64 RGB LED matrix
  • Power supply
  • LED driver board

Steps

  1. Install rpi-rgb-led-matrix.
  2. Write code to display:
    • Stock prices
    • Weather
    • Notification messages
  3. Mount LED display on a frame.

16. Automated Plant Watering System

Description

Monitor soil moisture and automatically water plants.

Materials

  • Raspberry Pi
  • Soil moisture sensor
  • Relay module
  • Water pump

Steps

  1. Connect the moisture sensor to GPIO.
  2. Write Python logic:
    • If moisture < threshold → activate pump.
  3. Log moisture readings.
  4. Add mobile notifications.

17. Pi-Powered Arcade Cabinet

Description

Build an actual arcade machine with joystick, buttons, and retro games.

Materials

  • Raspberry Pi 4 + RetroPie
  • Arcade joystick kit
  • Wood/MDF cabinet
  • HDMI monitor

Steps

  1. Assemble cabinet structure.
  2. Install joystick + buttons.
  3. Configure RetroPie for arcade controls.
  4. Install arcade ROMs and themes.

18. Private VPN Server

Description

Secure your home internet and access your network remotely.

Materials

  • Raspberry Pi 3/4
  • OpenVPN or WireGuard

Steps

  1. Install PiVPN: curl -L https://install.pivpn.io | bash
  2. Create client profiles.
  3. Install profiles on laptop/phone.
  4. Browse safely anywhere.

19. Personal Web Server (WordPress/LAMP)

Description

Host a website or blog from a Pi.

Materials

  • Raspberry Pi
  • Apache/Nginx
  • MariaDB
  • PHP

Steps

  1. Install LAMP stack: sudo apt install apache2 mariadb-server php php-mysql
  2. Install WordPress.
  3. Configure database and set up website.

20. Smart TV Box (Kodi / OSMC)

Description

Turn your Pi into a powerful streaming center.

Materials

  • Raspberry Pi 4
  • OSMC/Kodi software
  • Remote control or smartphone app

Steps

  1. Install OSMC.
  2. Add add-ons for:
    • YouTube
    • Netflix (with plugins)
    • Local media
  3. Customize UI and skins.

21. Pi Cluster for Learning Servers, Docker & Kubernetes

Description

Build a mini supercomputer to learn distributed computing.

Materials

  • 3+ Raspberry Pi boards
  • Ethernet switch
  • SD cards
  • Cluster case

Steps

  1. Install Raspberry Pi OS Lite on each node.
  2. Configure static IP addresses.
  3. Install Docker or Kubernetes (k3s).
  4. Deploy distributed workloads:
    • Web servers
    • Databases
    • Machine learning tasks

Conclusion

The Raspberry Pi is a powerhouse of creativity. From gaming and robotics to cloud computing and AI, its flexibility allows beginners and experts alike to build nearly anything they imagine. The 21 projects above cover a wide range of skill levels and interests, giving you everything you need to get started.