www.rodneybeede.com "I would love to change the world, but they won't give me the source code" - unknown
 Navigation

Linux script show VM IP on logon screen - Last Modified 2018-01-22 17:45 UTC - Created 2018-01-22 17:45 UTC

#!/bin/sh

# Care of http://offbytwo.com/2008/05/09/show-ip-address-of-vm-as-console-pre-login-message.html
#
# Modifications by Rodney Beede to have only 1 script file and some comments
#
# Debian/Ubuntu = /etc/network/if-up.d/show-ip-address
#	netplan = Add the following file too  /etc/systemd/system/show-ip-address.service
#	[Unit]
#	Wants=network-online.target
#	After=network-online.target
#
#	[Service]
#	ExecStart=/etc/network/if-up.d/show-ip-address
#
#	[Install]
#	WantedBy=multi-user.target
#
#
#  Also need to	systemctl enable show-ip-address
#
# CentOS/RHEL = /sbin/ifup-local
#
# chmod 700
# chown root:root

#


if [ "$METHOD" = loopback ]; then
    exit 0
fi


if [ ! -f /etc/issue-standard ]; then
	# First run so make our original to copy from each time
	cp /etc/issue /etc/issue-standard
fi

# Write a clean template copy for updating
cp /etc/issue-standard /etc/issue

# Add to end of template the value
ip address show | grep -Po 'inet \K[\d.]+' | grep -v 127.0.0.1 >> /etc/issue

# Add separation for login prompt that will follow
echo "" >> /etc/issue