Code Monkey home page Code Monkey logo

bashtruncatelogs's Introduction

bashTruncateLogs

Zero all files in /var/log/ courtesy of chatgpt + some of my tweaking to make stuff work.

Log Truncation Service

This repository contains a script, systemd service, and systemd timer that work together to periodically truncate log files in the /var/log directory.

Introduction

Logs can accumulate over time and consume disk space. This script automates the process of truncating log files, effectively clearing their content while retaining the file structure. The systemd service and timer ensure that this truncation process occurs regularly, preventing log files from growing excessively.

Installation

  1. Clone the Repository

    Clone this repository to your local machine:

    git clone https://github.com/your-username/log-truncation-service.git
    cd log-truncation-service
    

Create the Service Unit File

Create or modify the systemd service unit file:

sudo nano /etc/systemd/system/truncate-logs.service
Add the following content to the file:
[Unit]
Description=Periodically truncate log files in /var/log
After=network.target

[Service]
Type=simple
ExecStart=/path/to/your/script.sh
WorkingDirectory=/path/to/your/script/directory
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=default.target

Save and close the file.

Create the Timer Unit File

Create or modify the systemd timer unit file:

sudo nano /etc/systemd/system/truncate-logs.timer Add the following content to the file:

[Unit]
Description=Timer for truncating log files

[Timer]
OnCalendar=*:0/5
Persistent=true
Unit=truncate-logs.service

[Install]
WantedBy=timers.target

Save and close the file.

Reload systemd and Enable the Timer

sudo systemctl daemon-reload ;
sudo systemctl start truncate-logs.timer ;
sudo systemctl enable truncate-logs.timer ;

Check the Timer Status

To verify that the timer is running:

sudo systemctl status truncate-logs.timer
The script will now run once every 5 minutes to truncate log files in the /var/log directory.

##License This project is licensed under the MIT License.

Replace your-username, /path/to/your/script.sh, and /path/to/your/script/directory with the actual values corresponding to your system setup.

bashtruncatelogs's People

Contributors

tim0n3 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.