how can i get the username who invoked the shell script - Unix

This is a discussion on how can i get the username who invoked the shell script - Unix ; While writing a shell script i want to know the username who invoked the script so that i can compare it with the usernames given to me in a different file...

+ Reply to Thread
Results 1 to 10 of 10

Thread: how can i get the username who invoked the shell script

  1. how can i get the username who invoked the shell script

    While writing a shell script i want to know the username who invoked
    the script so that i can compare it with the usernames given to me in
    a different file


  2. Re: how can i get the username who invoked the shell script

    On Tue, 19 Jun 2007 06:51:49 -0700, GUNJAN SHARMA wrote:
    > While writing a shell script i want to know the username who invoked
    > the script so that i can compare it with the usernames given to me in
    > a different file


    man id

  3. Re: how can i get the username who invoked the shell script

    On Jun 19, 7:11 pm, Bit Twister wrote:
    > On Tue, 19 Jun 2007 06:51:49 -0700, GUNJAN SHARMA wrote:
    > > While writing a shell script i want to know the username who invoked
    > > the script so that i can compare it with the usernames given to me in
    > > a different file

    >
    > man id


    wen i try "man id"

    it gives following result

    sharmagu: man id
    getcwd: Stale NFS file handle



  4. Re: how can i get the username who invoked the shell script

    On 19 Jun., 15:51, GUNJAN SHARMA wrote:
    > While writing a shell script i want to know the username who invoked
    > the script so that i can compare it with the usernames given to me in
    > a different file


    Have a look at the manpages of id, who, whoami, ... what fits best
    (and your shell may support $USERNAME but that's unreliable in
    general and especially for your purpose).

    Janis


  5. Re: how can i get the username who invoked the shell script

    On Tue, 19 Jun 2007 07:15:37 -0700, GUNJAN SHARMA wrote:

    > wen i try "man id"
    >
    > it gives following result
    >
    > sharmagu: man id
    > getcwd: Stale NFS file handle


    Well, I'll not start debugging that. Here
    http://man.he.net/man1/id

  6. Re: how can i get the username who invoked the shell script

    2007-06-19, 07:16(-07), Janis:
    > On 19 Jun., 15:51, GUNJAN SHARMA wrote:
    >> While writing a shell script i want to know the username who invoked
    >> the script so that i can compare it with the usernames given to me in
    >> a different file

    >
    > Have a look at the manpages of id, who, whoami, ... what fits best
    > (and your shell may support $USERNAME but that's unreliable in
    > general and especially for your purpose).

    [...]

    The only shells that set a variable with a username AFAIK are:
    - zsh: $LOGNAME (as $(logname)), $USERNAME (as $(id -un))
    - tcsh: $user (as $(id -un))

    --
    Stéphane

  7. Re: how can i get the username who invoked the shell script

    GUNJAN SHARMA writes:

    > wen i try "man id"
    >
    > it gives following result
    >
    > sharmagu: man id
    > getcwd: Stale NFS file handle


    reboot your computer.

  8. Re: how can i get the username who invoked the shell script

    On Jun 20, 12:54 am, Maxwell Lol wrote:
    > GUNJAN SHARMA writes:
    > > wen i try "man id"

    >
    > > it gives following result

    >
    > > sharmagu: man id
    > > getcwd: Stale NFS file handle

    >
    > reboot your computer.


    Thanks a lot!!
    I am able to get it by "whoami" and "$LOGNAME"


  9. Re: how can i get the username who invoked the shell script

    On Wed, 20 Jun 2007 06:55:39 -0700, GUNJAN SHARMA wrote:
    > I am able to get it by "whoami" and "$LOGNAME"


    You may want to ignore $LOGNAME in your script.

    $ cat xx
    #!/bin/bash
    echo $LOGNAME

    $ ./xx
    bittwister

    $ export LOGNAME=easter_bunny

    $ ./xx
    easter_bunny

  10. Re: how can i get the username who invoked the shell script

    GUNJAN SHARMA writes:

    > On Jun 20, 12:54 am, Maxwell Lol wrote:
    > > GUNJAN SHARMA writes:
    > > > wen i try "man id"

    > >
    > > > it gives following result

    > >
    > > > sharmagu: man id
    > > > getcwd: Stale NFS file handle

    > >
    > > reboot your computer.

    >
    > Thanks a lot!!
    > I am able to get it by "whoami" and "$LOGNAME"


    To fix the stale NFS handle, you need to either reboot your computer,
    or unmount and remount the file system with the stale handle.

    reboot is the easiest solution.

+ Reply to Thread