Results 1 to 6 of 6

Thread: Knowing who is logged where

  1. #1
    Join Date
    Dec 2009
    Posts
    211

    Knowing who is logged where

    Hello
    I try to make a script to let me know a user who is connected on which machine. The idea is to avoid me having to make all rooms info when I was looking for someone. This is the final script, to call an argument with the person sought. Here machines are called up 01 MACHINE MACHINE 42.
    / bin / bash

    (function pqui
    users = $ (ssh MACHINE-$ 1 users)
    result = ""
    for user in $ users
    do
    ssh MACHINE-$ 1 w-s | egrep-q "$ user [[: blank:]] * tty7" & & result = $ result "$ user"
    done
    if [[! -z $ result]]
    then
    echo "MACHINE-$ 1: $ result
    fi
    )

    for i in $ (seq-f '% 02g' $ 1 NBPC);
    do
    pqui $ i &
    done
    wait
    exit 0;
    I have several problems.
    - How to make a single loop from 01 to 42? (for the moment I go from 1 to 9 zeros and then adding 10 to 42)
    - How to tell if a user is physically connected? (if I move and there's nobody my script has no interest)
    - How do nothing if no one is displayed on the machine?
    For the last 2 items I did not find anything by reading the man users. Basically users uses / var / run / utmp, but this file is unreadable. Thank you in advance.

  2. #2
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Knowing who is logged where

    Hi,
    I think you should modify your for loop, in this way
    for ((i = 1; i <= 42; i + +))
    do
    MACHINE echo $ (printf "% 02d \ n" "$ i")
    done
    This will be more effective than the current one in your code.

  3. #3
    Join Date
    Oct 2005
    Posts
    2,393

    Re: Knowing who is logged where

    Hello
    How to make a single loop from 01 to 42?
    for i in $ (seq-f '% 02g' 1 42);
    How do I know if a user is physically connected?
    I advise you to use the BSD finger command.
    sudo apt-get install bsd-finger
    It would obviously be installed on each machine but you can do with an order by combining ssh apt-get, yes, and a small loop.
    for user in $ (MACHINE ssh $ i-0 users)
    do
    $ result = $ (finger-s $ user)
    ...
    Hope this will help you.

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Knowing who is logged where

    Hello,
    How to display nothing if nobody is on the machine?
    Code:
    result = $ (MACHINE ssh $ i-0 users)
    if [[! -z $ result]]
      then echo $ result
    fi
    [[]] Is a shortcut for calling the test command. I invite you to read the documentation for this command: man test.
    Finally, the code should look like this:
    Code:
    for i in $ (seq-f '% 02g' 1 42)
    do
       users = $ (MACHINE ssh $ i-0 users)
       for user in $ users
       do
          $ result = (finger-s $ user)
    
       done
    done
    You must use the command awk and grep to parse the result returned by finger.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Knowing who is logged where

    Hello
    I found better than the finger command. The command w which is already available. Needless to install finger.
    The code now becomes:
    Code:
    for i in $ (seq-f '% 02g' 1 42)
    do
       users = $ (MACHINE ssh $ i-0 users)
       for user in $ users
       do
          result = $ (w-s | grep $ user)
    
       done
    done
    This may make your code better and easier to read.

  6. #6
    Join Date
    Apr 2008
    Posts
    2,005

    Re: Knowing who is logged where

    Hello
    I think there is no need to install any thing, this is unnecessary. Just have a look at the following code.
    Code:
    # '/ usr / bin / env bash
    
    for i in machine1 machine2
    do
        Who ssh $ i 2> / dev / null | egrep-q "^ $ 1 [[: blank:]] * tty7" & & (notify-send 'found' "$ i"; found on echo $ i) &
    done
    
    # wait
    exit 0
    I put each ssh in background to avoid waiting the end of each connection
    - Script starts with the user name as argument
    - Adapting to your loop for hostnames
    - Of course we can turn the notify-send if no interface Graphic
    - The wait (commented here) used to wait until all the ssh connections in the background to close the script, it is obviously necessary to connect ssh key if not impossible to enter the pass.

Similar Threads

  1. Knowing about Opera:Config
    By CheeCha in forum Technology & Internet
    Replies: 7
    Last Post: 26-02-2012, 06:54 PM
  2. hack a phone code without knowing it.
    By mkerengajames in forum Portable Devices
    Replies: 2
    Last Post: 19-01-2011, 03:07 AM
  3. knowing the advantages and disadvantages of using dell
    By Maybay in forum Portable Devices
    Replies: 4
    Last Post: 05-01-2011, 12:27 AM
  4. Knowing the use of CPU / memory
    By ISAIAH in forum Windows Software
    Replies: 5
    Last Post: 19-02-2010, 02:02 AM
  5. Knowing the IRQ sharing
    By Dr.pter in forum Operating Systems
    Replies: 3
    Last Post: 05-03-2009, 05:43 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,727,432,419.83983 seconds with 17 queries