3

I need to change the value of MOTD using a script but I do not know how I should start. Am attaching sample MOTD.

           enter image description here

  • 1
    Which unix variant (e.g. which distribution if Linux)? – Gilles Apr 25 '14 at 22:28
3

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 #
#                                                                                 #
###################################################################################
  • Hi slm, thanks it works, however i do not have the boxes tool, is there something like that i can use in aix? Many Thanks – batil Apr 25 '14 at 7:26
  • @zieggy - no idea. I would installed boxes or manually make a box myself and print the contents inside of it. – slm Apr 25 '14 at 12:03
  • thanks, generally answers my concern, will try to check how can i do the boxes! – batil Apr 28 '14 at 0:38
  • Is this dynamic ? Will the output change each time a user has logged in? – GC 13 Apr 26 '17 at 3:30
  • @GC13 - No, the date and uptime etc change every time the above command is run and written to /etc/motd. You need to create a cron job if you want this file to get periodically updated. – slm Apr 26 '17 at 3:35
1

If you want to generate dynamic MOTD, check out this up to date guide

https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/

Basically, you have to

1) create /etc/update-motd.d

2) place your script there

  • 1
    Please don't answer with 'check out this link'. Try to make the answer self-contained describing all necessary steps in details. Then just leave a link for a source at the end. – ddnomad Apr 10 '17 at 11:53
0

motd is simply a file. From man motd:

NAME
       motd - message of the day

DESCRIPTION
       The  contents  of  /etc/motd  are  displayed by login(1) after a successful
       login but just before it executes the login shell.

      The abbreviation "motd" stands for "message of the day", and this file has
      been traditionally used for exactly that (it requires much less disk space
      than mail to all users).

FILES
      /etc/motd

As a script point of view, something as simple as that would be enough:

#!/bin/sh
printf "     Welcome to $(hostname -s)\n\n" > /etc/motd
  • Hi Ouki, thanks, but i wanted to replace the content of the motd using a script, i forgot to say that the banner word "SERVER" should be the HOSTNAME of the lpar. – batil Apr 25 '14 at 1:29
  • More dynamic motd messages are OS dependent. What is your OS/distrib? – Ouki Apr 25 '14 at 1:39
  • Hi, my OS is AIX 7.1 – batil Apr 25 '14 at 1:49
  • How can i make the hostname will become a banner? – batil Apr 25 '14 at 1:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.