I've written a Perl script that connects to our central server for me and it allows me feed data so that I make a timesheet later. How do I run my script when I log out from Apple OS X or Linux / UNIX workstation using bash shell?
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
Edit $HOME/.bash_logout and add your command:
$ 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' 0
Save 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
You should follow me on twitter here or grab rss feed to keep track of new changes.
Featured Articles:
- 30 Handy Bash Shell Aliases For Linux / Unix / Mac OS X
- Top 30 Nmap Command Examples For Sys/Network Admins
- 25 PHP Security Best Practices For Sys Admins
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- Linux: 20 Iptables Examples For New SysAdmins
- Top 20 OpenSSH Server Best Security Practices
- Top 20 Nginx WebServer Best Security Practices
- 20 Examples: Make Sure Unix / Linux Configuration Files Are Free From Syntax Errors
- 15 Greatest Open Source Terminal Applications Of 2012

- My 10 UNIX Command Line Mistakes
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- The Novice Guide To Buying A Linux Laptop









![Unix Copy Command Examples [ cp command ]](http://s13.cyberciti.org/images/shared/rp/3/12.jpg)



{ 0 comments… add one now }