Skip to content

Instantly share code, notes, and snippets.

@seven62
Forked from dcode/00-README.adoc
Created February 28, 2017 16:27
Show Gist options
  • Save seven62/43bc724f41940137a6600057b43cb80b to your computer and use it in GitHub Desktop.
Save seven62/43bc724f41940137a6600057b43cb80b 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