[Linux] How to Auto-execute Commands or Programs at Login

Tadashi Shigeoka ·  Mon, September 5, 2011

I researched how to auto-execute commands or programs when logging into CentOS, so I’ll share the method.

Linux

When users want to execute their own programs at login, write shell scripts in the .bash_profile file.

I wanted to set up authenticated proxy with export and sync time with ntpdate at startup, so I did as follows:

.bash_profile (Before editing)

# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH
unset USERNAME

.bash_profile (After editing)

Added the following 2 lines at the end:

# Proxy authentication
export http_proxy=http://[username]:[password]@[IP address]:[port]/
# Time sync
ntpdate [IP address]

Now proxy authentication and time sync are automatically performed at login.

That’s all from the Gemba.