Automate common task with user login script.
Immediately after successfully logging in your dedicated server via the secure shell or a terminal window, there are many common repetitive initialization tasks that need to complete to set up an environment preference to adminsiter your server. This may include a customized search path that includes several subdirectories in your home directory, setting up the right colors for your terminal session, choice of a text editor, customizing the shell prompt, or displaying the current server's processes, to name a few. Linux can save a lot of typing for you by executing the required scripts once, immediately after each session login.

This section briefly illustrates how to automate common tasks via user login script. Following is an overview diagram of a typical Linux login scenario.

User login / SSH Login
|
System login script /etc/profile
|
User login script /home/brucelee/.bash_profile
|
Shell startup script /home/brucelee/.bashrc
|
User logged in (login complete)


Each user's home directory contains login script files (beginning with a dot). The following example shows the login script files in a typical Linux Fedora 9 installation. /etc/profile is executed followed by .bash_profile per every successful login. .bashrc is executed every time a new shell is started.

brucelee ~ % ls .bash* -alh
-rw------- 1 ldao ldao 12K 2008-11-06 10:10 .bash_history
-rw-r--r-- 1 ldao ldao 33 2008-09-29 07:05 .bash_logout
-rw-r--r-- 1 ldao ldao 176 2008-09-29 07:05 .bash_profile
-rw-r--r-- 1 ldao ldao 181 2008-11-06 10:10 .bashrc



The following commands are appended to the end of the file .bashrc to add the directory /usr/sbin and the login user directory's /scripts to the search path. The command prompt is customized and is displayed with a percent sign (%). The current server's processes are then displayed immediately after logging in.

# User specific aliases and functions
PATH=$PATH:/sbin:/usr/sbin:$HOME/scripts
PS1='\! \u \w % '
ps axu -AH