Created
November 11, 2024 04:18
-
-
Save cuongitl/c1858b55e1fe3ba62ccb6eb1bae0ebcb to your computer and use it in GitHub Desktop.
Shell Script to auto install vnStat on Linux
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Built with ❤️ by Cuongitl (LE VAN CUONG) | |
| # Telegram: https://t.me/Cuongitl | |
| # Filename: install-vnstat.sh | |
| # Modified: 2024-11-11 | |
| # Purpose: Install vnStat - a network traffic monitor for Linux | |
| # Exit the script if any command fails | |
| set -o errexit | |
| # Define the version of vnStat here | |
| VNSTAT_VERSION="2.12" | |
| # Install the required development libraries: | |
| sudo dnf install sqlite-devel # For Fedora 22+ or CentOS/RHEL 8+ | |
| # Set working directory to /usr/src | |
| cd /usr/src | |
| # Download vnStat source for the defined version | |
| echo "Downloading vnStat $VNSTAT_VERSION..." | |
| wget https://humdi.net/vnstat/vnstat-$VNSTAT_VERSION.tar.gz | |
| # Extract the downloaded tarball | |
| echo "Extracting vnStat $VNSTAT_VERSION..." | |
| tar zxvf vnstat-$VNSTAT_VERSION.tar.gz | |
| # Change to the vnStat directory | |
| cd vnstat-$VNSTAT_VERSION | |
| # Configure, build, and install vnStat | |
| echo "Configuring vnStat $VNSTAT_VERSION..." | |
| ./configure --prefix=/usr --sysconfdir=/etc | |
| echo "Building vnStat $VNSTAT_VERSION..." | |
| make | |
| echo "Installing vnStat $VNSTAT_VERSION..." | |
| make install | |
| # Copy the systemd service file | |
| echo "Copying systemd service file..." | |
| cp -v examples/systemd/vnstat.service /etc/systemd/system/ | |
| # Enable and start vnStat service | |
| echo "Enabling vnStat service..." | |
| systemctl enable vnstat | |
| echo "Starting vnStat service..." | |
| systemctl start vnstat | |
| # Check if vnstat service is running | |
| echo "Checking if vnStat service is running..." | |
| pgrep -c vnstatd | |
| echo "vnStat $VNSTAT_VERSION installation completed successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment