Getting IP address on logout

AntiRix

New Member
Joined
Mar 13, 2019
Messages
10
Reaction score
2
Credits
0
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.

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?
 


Most of our scripting enquiries are answered in Command Line, so I am moving this there for better attention.

Wizard
 

Staff online

Members online


Latest posts

Top