Skip to content

Instantly share code, notes, and snippets.

@dcode
Last active January 25, 2023 21:33
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save dcode/2c1b67c63147d0b0fdf021b34fcf2b3b to your computer and use it in GitHub Desktop.
Save dcode/2c1b67c63147d0b0fdf021b34fcf2b3b to your computer and use it in GitHub Desktop.

README

This is a CentOS-themed /etc/issue w/ hooks to update IP address and OS release upon ifup/ifdown. My motivation was that I was tired of logging into an otherwise headless box just to find the IP of the system so I can SSH to it.

Note
The issue.in file actually contains control characters to do the color in the text. The easiest way to preserve that is to clone this gist and run the install.sh script w/ sudo, which will copy the file and set the SELinux contexts.

Screenshot on console:

screenshot
Tip
You may also wanted to change /etc/ssh/sshd_config to point to /etc/motd instead of /etc/issue, but this is just user preference.
#!/bin/bash
# 90-issue-update
# Description: Updates /etc/issue using template /etc/issue.in and
# values from system at time of interface up
IF=$1
STATUS=$2
function update_issue() {
OS_RELEASE=$(cat /etc/redhat-release);
IP_ADDR=$(ip route get 255.255.255.255 | awk '{print $6 " ("$4")"; exit}')
cat /etc/issue.in | sed "s/{{OS_RELEASE}}/${OS_RELEASE}/;s/{{IP_ADDR}}/${IP_ADDR}/" > /etc/issue
# Reset gettys where a user is not logged in
GETTYS=$(systemctl list-units | grep "getty@" | grep -vE "$(who | awk '{ print $2 }'|paste -sd'|' )" | awk '{print $1}'|paste -s)
systemctl restart $(GETTYS)
}
if [ "$IF" <> "lo" ]
then
case "$2" in
up)
logger -s "NM Script up triggered"
update_issue
;;
down)
logger -s "NM Script down triggered"
update_issue
;;
*)
;;
esac
fi
#!/bin/sh
# Need to set proper SELinux contexts, we'll borrow from existing
# Need to run this with `sudo`
# Copy files from current directory
cp issue.in /etc/issue.in
cp 90-issue-update /etc/NetworkManager/dispatcher.d/
# Update SELinux contexts
chcon --reference /etc/issue{,.in}
chcon --reference /etc/NetworkManager/dispatcher.d/{11-dhclient,90-issue-update}
 .. 
 .PLTJ. 
 <><><><> 
KKSSV' 4KKK LJ KKKL.'VSSKK  Hostname:  \n
KKV' 4KKKKK LJ KKKKAL 'VKK  OS: {{OS_RELEASE}} 
V' ' 'VKKKK LJ KKKKV' ' 'V  Kernel: \s
.4MA.' 'VKK LJ KKV' '.4Mb.  Build: \v
 . KKKKKA.' 'V LJ V' '.4KKKKK .  IP Addr:  {{IP_ADDR}} 
 .4D KKKKKKKA.'' LJ ''.4KKKKKKK FA. 
 <QDD ++++++++++++ ++++++++++++ GFD> 
 'VD KKKKKKKK'.. LJ ..'KKKKKKKK FV 
 ' VKKKKK'. .4 LJ K. .'KKKKKV ' 
 'VK'. .4KK LJ KKA. .'KV'  Date: \d
A. . .4KKKK LJ KKKKA. . .4  Time: \t
KKA. 'KKKKK LJ KKKKK' .4KK  Users: \U
KKSSA. VKKK LJ KKKV .4SSKK 
 <><><><> 
 'MKKM' 
 ''
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment