[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: HOW can i get user ID
On Sun, Mar 26, 2000 at 02:26:14AM +0200, guy keren wrote:
> > HI everybody,
> > Can anybody tell me how can i get the usrid of the user when new user log
> > in to the linux system.. and how can i set the messege for him for first
> > time only. The messenge should not come when he login second time.
> > thanks..
>
> one simple way of showing a one-time message, is setting the user's
> '.cshrc' run a system-wide script, that maintains a small database of
> users who've already seen the message. this script will show the mesasge
> only if the user is not already in that database, and then update the
> database. this is ofcourse a bit risky, since the database needs to be
> world-writeable (as the script runs under the ID of this new user).
It also seems a bit slow, because every single interactive login does
this check.
> another method is put a script in the user's directory that's run via its
> '.cshrc', and then immediatly erased. this script will print out the
> welcome message.
Yes, something like this:
(your one-time message is in file "msg"; the following is from your
cshrc: )
echo blah
# do stuff
# Please do not touch this, it is magic xyzzy:
(cat msg && rm msg) || perl -0pi -e 's,\n(.*xyzzy),\n#$1,g' .cshrc
> one other option - there are packages on the net that do similar things.
> check out on freshmeat.net
Package!? This is a one-liner :-)
(note that this solution has two obvious flaws. The first is that
any line in your .cshrc contining the magic string will end up commented
out. That's probably okay, as users should not be faced with too much
potent magic anyway. The other is that the *second* run of the .cshrc
will spew out an error message from cat, and might scare off some users.
This is okay, because if they call you to complain, you can happily go
on being slightly bofhish (this not written with anyone particular in
mind, so no offence, anyone) and tell them to reproduce it. If they
could reproduce it, they can also fix it. (But they won't need to, since
they'll realize it won't happen to them again. Ah, the sweet longevity of
bugs.))
> as to finding the ID of the user - this depends on what you want to do
> with it. if this is just to personalize the message, use the '$USER'
> environment variable. if this is for other purposes, and you're afraid
> that users might abuse this, then just explain what you need it for.
Say you want to find info about a user 'byron' on your system:
% id byron
uid=577(byron) gid=535(romantics) groups=132(poets),535(romantics)
If you want to find a login name by real name:
% (cat /etc/passwd ; ypcat passwd) | grep 'Lord Byron' | awk -F: '{print $3}'
577
--
believing is seeing
gaal@forum2.org
http://www.forum2.org/gaal/
=================================================================
To unsubscribe, send mail to linux-il-request@linux.org.il with
the word "unsubscribe" in the message body, e.g., run the command
echo unsubscribe | mail linux-il-request@linux.org.il