Almost all modern shell including bash allows you run run command when you log out. Typically this is used to:
- Clean up screen with clear command.
- Remove history and other temporary file.
- Run commands or scripts and so on.
Logout file name
Commands in .logout are run when you log out.- bash shell: ~/.bash_logout
- tcsh / csh: ~/.logout
$ vi ~/.bash_logout
Sample logout configuration:
if [ "$SHLVL" = 1 ]; then
#clear screen
[ -x /usr/bin/clear_console ] && /usr/bin/clear_console -q
# delete mysql history
[ -f $HOME/.mysql_history ] && /bin/rm $HOME/.mysql_history
# Update ip accounting
[ -x /usr/bin/ip_accouting ] && /usr/bin/ip_accouting -u "$USER" -a
# call your script here
[ -x /usr/local/bin/timesheet_client.pl ] && /usr/local/bin/timesheet_client.pl
fi
A Note About Old Shell And Bourne / KSH Shell
Older UNIX shell and the Bourne / ksh shell don't have a logout file. So edit ~/.profile file, enter:$ vi ~/.profile
Next append the following line:
trap '. $HOME/.my_shell_logout; exit' 0Save and close the file. Finally create $HOME/.my_shell_logout, enter:
$ vi $HOME/.my_shell_logout
Sample config
# call your script here
if [ -f /usr/local/bin/timesheet_client.pl ]
then
/usr/local/bin/timesheet_client.pl
fi
No comments:
Post a Comment