0

is it possible to segregate different motd files for different users ? So Admin gets a different message and others diff one....

3
  • Dumb question: Why don't you put the display command in ~/.profile or ~/.kshrc (or ~/.bashrc or whatever shell you use for each user) ?
    – doktor5000
    Sep 17, 2015 at 19:37
  • we Use LDAP in the Environment.. which uses /etc/.profile for all the users... in normal environment we have .profile in the /home/users/$id/ directory... which is not... in my case...
    – Sivas
    Sep 18, 2015 at 11:15
  • You should have added such details to the original question, how are others supposed to know that?
    – doktor5000
    Sep 18, 2015 at 20:16

2 Answers 2

1

After a long search, I came up with the idea:

edit the /etc/profile and add the below loop to the end but before TRAP..

#!/bin/ksh
ROOTY=$(whoami)
if [ ${ROOTY} != root ] ; then
    for i in `who am i |awk {'print $1'}` 
    do
        RID=$i
        UNIXADM=$(sudo cat /home/root/unixusers | grep -Fx $RID | wc -l)
        if [ ${UNIXADM} == 1 ] ; then
            cat /etc/motd.unixusers
        fi
    done
fi

where /home/root/unixusers will be the user list /etc/motd.unixusers is the user specific motd

0
1

that looks over complex to me

ROOTY=$(whoami)
if [ ${ROOTY} != root ]
then
   if sudo grep -q $ROOTY /home/root/unixusers
   then cat /etc/motd.unixusers
   else cat /etc/motd
   fi
fi

please note that

  • whoami and who am i |awk {'print $1'} are likely to give same result
  • sudo cat /home/root/unixusers | grep -Fx $RID | wc -l is equivalent to sudo grep -c $RID /home/root/unixusers
  • however, you compare to 1, why not take result from grep ?
  • why run a loop for one item ?
3
  • test123:root:/home/root # who am i sivas123 pts/0 18 Sep 11:59 (test.test.com) test123:root:/home/root # whoami root test123:root:/home/root #
    – Sivas
    Sep 18, 2015 at 11:13
  • who am i & whoami are two different commands @jeff Schaller I have to make sure, only the users in the list has to get the message... not every user in the server... only specific users in the list... so when i cat and grep with -Fx it will be the exact match in the list.. and the count will be either 0 or 1.. so if it is 1 then message displays.. 0 no message.. and when you sudo su to root... same profile is loaded in LDAP environment... so i have to make sure.. this for loop should not display the motd... during sudoing...... make sense ? ;-)
    – Sivas
    Sep 18, 2015 at 11:20
  • Interesting, I never have use ldap environment in Linux (now I have to), thus maybe who am i | awk '{print $1}' and whoami give two differente result.
    – Archemar
    Sep 18, 2015 at 11:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .