As we have discussed about vnstat installation on previous post, the following shell script will help you to install in your system (CentOS / Fedora / RHEL) automatically,
Create a file with the name of vnstat-installation.sh and give execute permission,
# vim vnstat-installation.sh
# chmod +x vnstat-installation.sh
# chmod +x vnstat-installation.sh
Shell Script:
### VNSTAT Installation Shell Script ###
#!/bin/sh
### Get active interface
ETHDEV_NAME=`ip link show | grep 'state UP' | awk '{print $2}' | cut -d ':' -f1`
### Find out whether vnstat installed or not
VNSTAT_PATH=`whereis vnstat | awk '{print $2}'`
if [ ! -f $VNSTAT_PATH ]; then
### Find 64 bit or 32 bit and install rpm repo
if $(getconf LONG_BIT | grep '64'); then
rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
else
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
fi
### Install vnstat package using yum command
yum install vnstat -y
vnstat -u -i $ETHDEV_NAME
### Set cron job
echo "00 12 * * * /usr/bin/vnstat -u" >> /var/spool/cron/root
/etc/init.d/crond restart
###Get vnstat Version
vnstat -v
else
echo "VNSTAT Package Installed in your system."
exit;
fi
#!/bin/sh
### Get active interface
ETHDEV_NAME=`ip link show | grep 'state UP' | awk '{print $2}' | cut -d ':' -f1`
### Find out whether vnstat installed or not
VNSTAT_PATH=`whereis vnstat | awk '{print $2}'`
if [ ! -f $VNSTAT_PATH ]; then
### Find 64 bit or 32 bit and install rpm repo
if $(getconf LONG_BIT | grep '64'); then
rpm -Uvh http://packages.sw.be/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
else
rpm -Uvh http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.2-2.el6.rf.i686.rpm
fi
### Install vnstat package using yum command
yum install vnstat -y
vnstat -u -i $ETHDEV_NAME
### Set cron job
echo "00 12 * * * /usr/bin/vnstat -u" >> /var/spool/cron/root
/etc/init.d/crond restart
###Get vnstat Version
vnstat -v
else
echo "VNSTAT Package Installed in your system."
exit;
fi
Execute the script,
# ./vnstat-installation.sh
or
# sh vnstat-installation.sh
or
# sh vnstat-installation.sh
Comments (0)