Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Interactive Login Session

Options
  • 29-01-2018 12:01pm
    #1
    Closed Accounts Posts: 1,758 ✭✭✭


    If given a list of running processes in Linux, how do you determine which are an interactive login session?

    I've been given this very basic task but I don't even know what an interactive login session is or how to identify one.

    Any help please?


Comments

  • Registered Users Posts: 23,212 ✭✭✭✭Tom Dunne


    What processes handle logins?


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Ugly but functional...
     ps auxf|perl -ne '@r=split;if(!$l){$l=1 if $r[10]=~/^\/usr\/sbin\/sshd$/;$aps++}else{$lps++;$l=0 if $r[10]!~/^\\/}}{print "live:$lps\tauto:$aps\n"' -
    


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Pelvis wrote: »
    If given a list of running processes in Linux, how do you determine which are an interactive login session?

    I've been given this very basic task but I don't even know what an interactive login session is or how to identify one.

    Any help please?

    I wouldn't call that a basic task, it's actually not a straightforward thing to do. Here's a good place to start on getting to know the differences:

    https://unix.stackexchange.com/questions/50665/what-is-the-difference-between-interactive-shells-login-shells-non-login-shell

    Do you have any more specific details on what you need to do? That's a very high level request with lots of potential gotchas.
    Ugly but functional...
     ps auxf|perl -ne '@r=split;if(!$l){$l=1 if $r[10]=~/^\/usr\/sbin\/sshd$/;$aps++}else{$lps++;$l=0 if $r[10]!~/^\\/}}{print "live:$lps\tauto:$aps\n"' -
    

    This is a somewhat good place to start. To explain how this actually works;
    • It runs the command ps auxf
    • Looks for any process running under the SSH daemon (/usr/sbin/sshd)
    • Counts the number of subprocesses, and returns that count.

    However there's a number of assumptions happening here:
    • The only login sessions are over SSH.
    • The ssh daemon is running from /usr/sbin/sshd
    • A login shell is also an interactive shell

    So this returns the wrong result on my system as I have a local interactive login session that's not over ssh, and also my ssh daemon runs from /usr/bin rather than /usr/sbin. It also just gives a total count rather than identifying what the processes actually are.


  • Closed Accounts Posts: 1,758 ✭✭✭Pelvis


    Thanks for the responses guys.

    I started back in classes for the semester last week and the first lab for one module is getting us all back into using the command line, so there's a number of exercises to do based on a couple of text files. The general idea is to get us familiar with cat/grep/awk/pipelines and the like.

    So, I don't have to identify interactive login sessions on my local machine, just to identify and count them from the txt file attached. I had assumed SSH daemon was one, but no idea about the others, or what even constituted an interactive session.


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Pelvis wrote: »
    Thanks for the responses guys.

    I started back in classes for the semester last week and the first lab for one module is getting us all back into using the command line, so there's a number of exercises to do based on a couple of text files. The general idea is to get us familiar with cat/grep/awk/pipelines and the like.

    So, I don't have to identify interactive login sessions on my local machine, just to identify and count them from the txt file attached. I had assumed SSH daemon was one, but no idea about the others, or what even constituted an interactive session.


    Ah, that's a bit more reasonable. So here's a snippet from the file:
    root       410     2  0 22:28 ?        00:00:00 [kworker/0:2]
    arch       411   307  0 22:28 tty1     00:00:00 ps -ef
    

    Do you know what each of the columns means? That should help narrow down what processes you are looking for, especially if you have a read through the stackoverflow post I linked earlier.


  • Advertisement
  • Registered Users Posts: 2,719 ✭✭✭niallb


    I'd need to add nxserver and moshd as well for several machines.
    Though nxserver would match on sshd for transport, it wouldn't give the logged in username.


  • Closed Accounts Posts: 534 ✭✭✭eezipc


    I've been working with Ubuntu and red hat for years but I would have to Google that. Great thing with Linux is that answers are easy to find.


  • Closed Accounts Posts: 1,758 ✭✭✭Pelvis


    deconduo wrote: »
    Ah, that's a bit more reasonable. So here's a snippet from the file:
    root       410     2  0 22:28 ?        00:00:00 [kworker/0:2]
    arch       411   307  0 22:28 tty1     00:00:00 ps -ef
    

    Do you know what each of the columns means? That should help narrow down what processes you are looking for, especially if you have a read through the stackoverflow post I linked earlier.

    So, anything in the TTY column <> ? is an interactive session as these are processes that take user input, where as all the other processes are automated and thus not interactive?
    arch       307   172  0 21:53 tty1     00:00:00 -bash
    arch       411   307  0 22:28 tty1     00:00:00 ps -ef
    

    Though, the question put to me is asking for "interactive login sessions", and going by that link you posted the examples of 'login' and 'interactive' seem like they're mutually exclusive?

    Looking at this answer, the only interactive login shell in the processes I posted would be the SSH process?


  • Moderators, Computer Games Moderators Posts: 4,281 Mod ✭✭✭✭deconduo


    Pelvis wrote: »
    So, anything in the TTY column <> ? is an interactive session as these are processes that take user input, where as all the other processes are automated and thus not interactive?
    arch       307   172  0 21:53 tty1     00:00:00 -bash
    arch       411   307  0 22:28 tty1     00:00:00 ps -ef
    

    Though, the question put to me is asking for "interactive login sessions", and going by that link you posted the examples of 'login' and 'interactive' seem like they're mutually exclusive?

    Looking at this answer, the only interactive login shell in the processes I posted would be the SSH process?

    I think you might be mixing things up slightly. Most user sessions are both login and interactive.

    You are correct in the first point, the two processes running by the 'arch' user, (which have a tty) are the ones you are looking for. The rest are system processes.

    They are both login and interactive processes. The '-' in front of the bash process denotes that its a login shell, and the 'ps -ef' is a subprocess of the bash shell (If you look at the process IDs you can confirm this)


Advertisement