Last active
September 18, 2020 07:29
-
-
Save ngyuki/0eec312980770a34be42 to your computer and use it in GitHub Desktop.
auto generate issue for centos6
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 | |
# | |
### BEGIN INIT INFO | |
# Required-Start: $network | |
# Should-Start: $network | |
# Default-Start: 2 3 4 5 | |
# Default-Stop: 0 1 6 | |
### END INIT INFO | |
# | |
# chkconfig: 2345 98 02 | |
# description: autoissue | |
# | |
. /etc/init.d/functions | |
function err() | |
{ | |
echo "command notfound $1" 1>&2 | |
exit 1 | |
} | |
function has() | |
{ | |
type "$1" 1> /dev/null 2>&1 | |
} | |
[ "$EUID" -eq 0 ] || err "this script is root only" | |
has ip || err "ip command notfound" | |
has perl || err "perl command notfound" | |
if has banner; then | |
function print_banner() { | |
banner " $1.$2" " $3.$4" | |
} | |
elif has figlet; then | |
function print_banner() { | |
figlet -f banner " $1 . $2"$'\n'" . $3 . $4" | |
} | |
else | |
err "banner or figlet command notfound" | |
fi | |
function start() { | |
sed -i -ne '/^===*/q;p' /etc/issue | |
{ | |
echo '===' | |
print_banner $( | |
ip -o route get 255.255.255.255 | | |
perl -nle 'print "$1 $2 $3 $4" if /\s+src\s+(\d+)\.(\d+)\.(\d+)\.(\d+)/' | |
) | |
} >> /etc/issue | |
echo -n "Auto issue generate" | |
success | |
echo | |
#pkill agetty 1>/dev/null 2>&1 | |
#pkill mingetty 1>/dev/null 2>&1 | |
} | |
function stop() { | |
sed -i -ne '/^===*/q;p' /etc/issue | |
echo -n "Auto issue restore" | |
success | |
echo | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
status) | |
;; | |
*) | |
echo $"Usage: $0 {start|stop|status}" | |
exit 2 | |
esac | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment