Skip to content

Instantly share code, notes, and snippets.

@bilalatli
Created March 16, 2020 13:54
Show Gist options
  • Select an option

  • Save bilalatli/cfbe19d65223b6f8715519e2c3604e7f to your computer and use it in GitHub Desktop.

Select an option

Save bilalatli/cfbe19d65223b6f8715519e2c3604e7f to your computer and use it in GitHub Desktop.
SSH - Session Record
if [ "x$REC_START" = "x" ]
then
TTY_CON=$(tty | cut -d '/' -f3)/$(tty | cut -d '/' -f4)
TTY_IP=$(who | grep "${TTY_CON}" | cut -d ' ' -f16 | tr -d '()')
TTY_USER=$(last | grep "still logged in" | grep "$TTY_IP" | grep "$TTY_CON" | cut -d ' ' -f1 | tr -d ' ')
output=/var/log/session/rec_$(date +%F_%H-%M-%S)_$TTY_USER_$USER.$TTY_IP
REC_START=started
export REC_START
script -t -f -q 2>${output}.timing $output
exit
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment