I have a shell script that has to be ran when a user logs in, but when he tries to get out of the script, he should be logged out again.
The script uses dialog to create a TUI and is working fine when I run it and even when I set it in .bashrc . When I use putty no issue at all. When I go trough VMWARE or HYPERV console and login with the user it looks like he is making a loop and nothing can be done. The TUI is shown but refreshing constantly.
When I run the script in .bashrc without exec in front of it, it is also working fine. But when I quit the script, the user is still logged in.
I have tried on different systems (VMWARE, HYPERV): this has the same behaviour
One thing you might want to try is adding a trap to your script that catches the signal when the user tries to exit the TUI. You can then use this trap to log the user out of the system.
Here's an example of what that might look like:
#!/bin/bash
# Set up trap to catch exit signal
trap "logout" SIGINT SIGTERM
# Function to log user out
logout() {
echo "Logging out..."
pkill -KILL -u $USER
}
# Your TUI code here
This should catch the signal when the user tries to exit the TUI and log them out of the system.