Purchase Linux CDs / DVDs / Flash Drives at OSDisc.com

Welcome to Our Community

While Linux.org has been around for a while, we recently changed management and had to purge most of the content (including users). If you signed up before April 23rd, 2017 please sign up again. Thanks!

  1. More ways to get the info! - we shoot all of our new original content out as well as random messages on Twitter and our newsletter!. Twitter | Newsletter
    Dismiss Notice

Getting IP address on logout

Discussion in 'Command Line' started by AntiRix, Mar 14, 2019.

  1. AntiRix

    AntiRix New Member

    Joined:
    Mar 13, 2019
    Messages:
    10
    Likes Received:
    2
    Hi,

    I've managed to write a script which logs whether or not a connection is via SSH or direct, along with the IP address of the connecting party, but I can't get it to work the same on logout.


    (Log in to hide this advertisement)


    I created a script at ~/.logout which is called via
    Code:
    trap '$HOME/.logout' 0
    in ~/.profile. The script is called, but it seems $SSH_CONNECTION is undefined at that point, so it's reporting SSH connections as not via SSH.

    ~/.logout:
    Code:
    #!/bin/sh
    
    if [[ -n $SSH_CONNECTION ]] ; then
            (/var/www/html/logging/logout-report ssh $(echo $SSH_CONNECTION | awk '{print $1}') &)
    else
            (/var/www/html/logging/logout-report direct &)
    fi
    
    exit 0
    I can only imagine that the SSH connection is closed by the time this script is run. Is there any way around this?
     
  2. wizardfromoz

    wizardfromoz Super Moderator
    Staff Member Gold Supporter

    Joined:
    Apr 30, 2017
    Messages:
    2,982
    Likes Received:
    2,348
    Most of our scripting enquiries are answered in Command Line, so I am moving this there for better attention.

    Wizard
     

Share This Page