Change motd value in UNIX Operating System

To generate a MOTD in the style you're showing in your example you'll likely want to make use of the banner command. You can feed it the output from the hostname command to get a nice banner of your server's name.

To make this your MOTD you'll simply want to direct the output from these command to the file /etc/motd, which is what's used for displaying the MOTD.

$ ...cmd... > /etc/motd

NOTE: The commands I'm going to show below can be swapped into ...cmd....

Example

$ banner $(hostname)

 #####   ######   #######  #######  #     #  #######   #####    #####   
#     #  #     #  #        #        ##    #  #        #     #  #     #  
#        #     #  #        #        # #   #  #        #        #        
#  ####  ######   #####    #####    #  #  #  #####    #  ####  #  ####  
#     #  #   #    #        #        #   # #  #        #     #  #     #  
#     #  #    #   #        #        #    ##  #        #     #  #     #  
 #####   #     #  #######  #######  #     #  #######   #####    #####   

This one liner will give you nearly what you want:

$ (banner "server"; \
    printf "Hostname: %s\nDate    : %s\nUptime  :%s\n\n", \
    "$(hostname -s)" "$(date)" "$(uptime)")

 #####   #######  ######   #     #  #######  ######   
#     #  #        #     #  #     #  #        #     #  
#        #        #     #  #     #  #        #     #  
 #####   #####    ######   #     #  #####    ######   
      #  #        #   #     #   #   #        #   #    
#     #  #        #    #     # #    #        #    #   
 #####   #######  #     #     #     #######  #     #  

Hostname: greeneggs
Date    : Thu Apr 24 22:39:23 EDT 2014
Uptime  : 22:39:23 up 3 days,  8:34,  6 users,  load average: 0.80, 1.06, 1.49

Printing boxes

In addition to using the command line tool banner to print banner text, you can use another helper tool called boxes to wrap a box around arbitrary text.

$ boxes -d shell -p a1l2 <(hostname -s)
##############
#            #
#  greeneggs #
#            #
##############

We can use this approach and scale it up to do what you want like so:

$ boxes -d shell -p a1l2 \
    <(banner "server"; \
        printf "Hostname: %s\nDate    : %s\nUptime  :%s\n" \
        "$(hostname -s)" "$(date)" "$(uptime)")
###################################################################################
#                                                                                 #
#                                                                                 #
#   #####   #######  ######   #     #  #######  ######                            #
#  #     #  #        #     #  #     #  #        #     #                           #
#  #        #        #     #  #     #  #        #     #                           #
#   #####   #####    ######   #     #  #####    ######                            #
#        #  #        #   #     #   #   #        #   #                             #
#  #     #  #        #    #     # #    #        #    #                            #
#   #####   #######  #     #     #     #######  #     #                           #
#                                                                                 #
#  Hostname: greeneggs                                                            #
#  Date    : Thu Apr 24 22:54:09 EDT 2014                                         #
#  Uptime  : 22:54:09 up 3 days,  8:49,  6 users,  load average: 0.63, 0.81, 1.09 #
#                                                                                 #
###################################################################################

Tags:

Scripting

Motd