0

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:

#!/bin/bash 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:

exit or logout or $(logout) 

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.

1 Answer 1

1

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 exit 

Happy logging of your users!

2
  • Thank you it's working that way. This is usefull to check what are doing my students! Commented Sep 16, 2017 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). Commented Sep 16, 2017 at 19:18

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.