Posted in

vnStat data traffic on Ubuntu login

Display data traffic statistics and estimates from vnStat for today and the current month on your Ubuntu Server login motd aka ‘message of the day.’

1. Install vnStat

 
sudo apt-get install vnstat
sudo vnstat -i eth0 -u --enable

2. Add the script 60-vnstat to the motd

The number decides the position on the motd message. For example, 50 is the system info like system load and memory usage, and 90 is the update checker.

First write the script:

 
sudo nano /etc/update-motd.d/60-vnstat
 
#!/bin/sh
vn="/usr/bin/vnstat -i eth0 -s"
echo
$vn | head -n 2 | tail -n 1 # header
$vn | tail -n 2 | head -n 1 # today
$vn | head -n 5 | tail -n 1 # month

Then make it executable:

 
sudo chmod 755 /etc/update-motd.d/60-vnstat

3. Logoff and login again :)

Leave a Reply

Your email address will not be published. Required fields are marked *