Created
September 10, 2014 16:29
-
-
Save leonjza/d2e6b87051b2f30e7e3f to your computer and use it in GitHub Desktop.
Show current IP on TTY login prompt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
On a fast SSD machine, i need to add a "sleep 15s" in the rc.local:
or i get "no active connection found"