10.16
Have you ever wanted to create a custom message to be displayed on the Linux pre-login console, which is dynamically updating?
Well, this tutorial will help you do it. I’ve only tested this on Ubuntu 8.04, so please let me know if it works for other distributions. Thanks!
First, create a shell script to re-generate the /etc/issue file. For this example, I’ll create a message that shows how to access the webmin interface. Add this code to a file called /etc/init.d/new_issue.sh:
#!/bin/bash
######################################################
# Prints login/port info above console login prompt. #
######################################################
# get configured IP for eth0
IPADDR=$(/sbin/ifconfig eth0 | sed -n 's/.*inet *addr:\([0-9\.]*\).*/\1/p')
# generate new /etc/issue
/bin/echo "Ubuntu 8.04.3 LTS \n \l" > /etc/issue
/bin/echo >> /etc/issue
/bin/echo "************************************************" >> /etc/issue
/bin/echo "Webmin: https://$IPADDR:12345" >> /etc/issue
/bin/echo "************************************************" >> /etc/issue
/bin/echo >> /etc/issue
exit 0
Once that’s done, issue the following commands to make the script executable, and tell Linux to run as one of the last scripts in the default runlevels:
[root@linux]$ chmod 755 /etc/init.d/new_issue.sh
[root@linux]$ update-rc.d new_issue.sh defaults 99
This should now replace the default issue message with your custom one. Then reboot, and you should see your new custom message sitting just above your console login!
Optionally, for a script that runs as a daemon, constantly polling data and updating /etc/issue, I would actually recommend converting this to a perl script, and use the following code to daemonize the perl script:
# begin damonization close(STDIN); close(STDOUT); close(STDERR); exit if (fork()); exit if (fork()); while(1) { # # put the converted code here # sleep 30; }