Skip to content

Instantly share code, notes, and snippets.

@leonjza
Created September 10, 2014 16:29
Show Gist options
  • Save leonjza/d2e6b87051b2f30e7e3f to your computer and use it in GitHub Desktop.
Save leonjza/d2e6b87051b2f30e7e3f to your computer and use it in GitHub Desktop.
Show current IP on TTY login prompt
#!/bin/bash
#
# bootprompt.sh
#
# Description: Shows connected interface(s) at boot and related ip address(es) on tty login prompt
# Usage: Put it somewhere (ie. /etc/init.d/) and then add its full path entry to /etc/rc.local
DSTFILE="/etc/issue"
KEEPLINE=$(head -n 1 ${DSTFILE})
IFACE_UP=$(/sbin/ifconfig eth0 | grep 'Bcast:' -B1 | grep -v inet | grep -v - -- | awk '{print $1}')
echo ${KEEPLINE} | sed 's/\\\\/\\/g' > ${DSTFILE}
echo >> $DSTFILE
if [ -z "$IFACE_UP" ]; then
echo "\n No active connection found." >> $DSTFILE
else
echo "Currently connected via:">> $DSTFILE
for IFACE in $IFACE_UP;
do IPADDR=$(/sbin/ifconfig $IFACE | grep 'Bcast:' | cut -d: -f2 | awk '{ print $1}')
echo " $IFACE $IPADDR" >> $DSTFILE
done
fi
echo >> $DSTFILE
exit 0
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/etc/init.d/bootprompt.sh
exit 0
@BurtGummer
Copy link

On a fast SSD machine, i need to add a "sleep 15s" in the rc.local:

sleep 15s
/etc/init.d/bootprompt.sh
exit 0

or i get "no active connection found"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment