In the .profile of each user of the system (debian 8), I call a script who start a typescript session, to log everything in a file:


script -f $HOME/.log/$(date +"%d-%b-%y_%H-%M-%S")_shell.log

The thing is when you enter "exit" then, you just stop the typscrit session, not the ssh connection, so you have to enter exit again. I would like to close ssh connection when we exit the typescript by enter "exit". I tried differents things:

At the end of my script:


All of this return an error after exiting the typescript, for instance with logout or $(logout):

/pathtoscript/log.sh: 9: /pathtoscript/log.sh: logout: not found

But it's a system command so I just need to execute this in system at the end of the script and that should be good!

in .bashrc:

function exit() { builtin exit && exit; }

Nothing append with this function, when I hit "exit" the typescript stop but not the ssh session.


Your stuff doesn't work the way you want it, but exactly as you told it:

.profile is sourced by your shell, just as if you would have typed each character by hand. If you execute a script or other program in your shell, you expect to return to your prompt as soon as it has finished. This is exactly what you are experiencing.

You can put an exit into your .profile and it will exit as if you had typed it in an interactive shell. Your .profile might look like this then:

# ... whatever comes before
script -f $HOME/.log/$(date +"%d-%b-%y_%H-%M-%S")_shell.log

Happy logging of your users!

  • Thank you it's working that way. This is usefull to check what are doing my students! – poka Sep 16 '17 at 13:03
  • Using exec script ... should also work, since it replaces the shell with the script program (and thus there's no shell to exit at the end). – Gordon Davisson Sep 16 '17 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.