Alias and Script to start DHCP and Xen VM

January 21st, 2012

I wanted to create a bash script which started a dhcp server daemon and also started a Xen virtual machine. The script would be tiny and it would be executed using an alias, which I added to my bashrc.

Here is the script:

[root@shimla ~]# cat
/etc/init.d/dhcpd start
cd /etc/xen
xm create Elastix-PBX

[root@shimla ~]#

Change permissions:

[root@shimla ~]# chmod 777
[root@shimla ~]#

Edit ~/.bashrc to add an alias of “go” for the command “./” (see further below)

alias go=’./’

Test (need to logout and back in to read bash profile again):

[root@shimla ~]# go
Starting dhcpd: [ OK ]
Using config file “./Elastix-PBX”.
Started domain Elastix-PBX
[root@shimla ~]#

Linux startup files explained:
These files contain the aliases and environmental variables made available to Bash running as a user shell and to all Bash scripts invoked after system initialization:


These are systemwide defaults, mostly setting the environment (all Bourne-type shells, not just Bash)


These are systemwide functions and aliases for Bash


These are user-specific Bash environmental default settings, found in each user’s home directory (the local counterpart to /etc/profile)


These are user-specific Bash init file, found in each user’s home directory (the local counterpart to /etc/bashrc). Only interactive shells and user scripts read this file.

Here are the contents of my startup files.

[root@shimla init.d]# cat ~/.bashrc
# .bashrc

# User specific aliases and functions with “” alias (“go”) added:

alias rm=’rm -i’
alias cp=’cp -i’
alias mv=’mv -i’
alias go=’./’

# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
[root@shimla init.d]#

[root@shimla init.d]# cat ~/.bash_profile
# .bash_profile

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

# User specific environment and startup programs


export PATH
[root@shimla init.d]#

Linux logout files:

These are user-specific instruction file, found in each user’s home directory. Upon exit from a login (Bash) shell, the commands in this file execute.

Comments are closed.