The Cookie Machine - Click here to drag window

DUMMY TEXT - Real text set in assets/js/theCookieMachine.js

Views: 4,193β€…    Votes:  4β€…
Link: πŸ” See Original Answer on Ask Ubuntu πŸ”—

URL: https://askubuntu.com/q/1025026
Title: Is it possible to show ip address on top bar near the time?
ID: /2018/04/14/Is-it-possible-to-show-ip-address-on-top-bar-near-the-time_
Created: April 14, 2018
Upload: November 24, 2022    Layout:  post
TOC: false    Navigation:  false    Copy to clipboard:  false


Screenshot

indicator sysmonitor screenshot.png

Discover your current DCHP IP address

This answer should work for most Ubuntu distributions. The first step is discovering your current IP address. According to this Linux & Unix answer it isn’t stored on disk in the same location across distributions. For a portable solution you need to use:

default_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8; exit}')
ip_address=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}')
echo $ip_address
192.168.1.66

Install Sysmonitor Indicator

You now need an Application Indicator that to let’s you pick and choose the information to display in the Systray / Application Notification Area. I use Sysmonitor Indicator. To summarize the installation instructions in the link:

sudo add-apt-repository ppa:fossfreedom/indicator-sysmonitor
sudo apt-get update
sudo apt-get install indicator-sysmonitor

You need to configure the name of the bash script that is called and the update interval in the Advanced tab of the Preferences panel:

indicator sysmonitor custom.png

Highlight the Custom option and click the Edit button:

indicator sysmonitor custom edit.png

Here’s a complaint I have to the developer the input field for the command is abnormally small. You can’t see the whole command you are typing all at once and need arrow keys to scroll through it. Anyway assign the bash script filename. I used:

~/bin/indicator-sysmonitor-display

I already have a main bash script so I created an abbreviated version for this answer.

Create the script

Using the code from the first section create the file ~/bin/indicator-sysmonitor-display containing:

#!/bin/bash

default_interface=$(route -n | awk '$1 == "0.0.0.0" {print $8; exit}')
systray=$(ifconfig "$default_interface" | awk 'sub(/.* inet addr:/, "") {print $1}')

echo "$systray" # sysmon-indidicator will put echo string into systray for us.

exit 0
⇧ How can I see previous history (prior to this boot) in journalctl? Cron job - need script to start VPN if not already running for job  β‡©