{"id":1433,"date":"2012-01-21T10:59:35","date_gmt":"2012-01-21T10:59:35","guid":{"rendered":"http:\/\/mccltd.net\/blog\/?page_id=1433"},"modified":"2012-01-21T17:33:30","modified_gmt":"2012-01-21T17:33:30","slug":"alias-and-script-to-start-dhcp-and-xen-vm","status":"publish","type":"page","link":"http:\/\/darenmatthews.com\/blog\/?page_id=1433","title":{"rendered":"Alias and Script to start DHCP and Xen VM"},"content":{"rendered":"<p>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.<\/p>\n<p>Here is the script:<\/p>\n<blockquote><p>[root@shimla ~]# cat start.sh<br \/>\n#!\/bin\/bash<br \/>\n\/etc\/init.d\/dhcpd start<br \/>\ncd \/etc\/xen<br \/>\nxm create Elastix-PBX<\/p>\n<p>[root@shimla ~]#<\/p><\/blockquote>\n<p>Change permissions:<\/p>\n<blockquote><p>[root@shimla ~]# chmod 777 start.sh<br \/>\n[root@shimla ~]#<\/p><\/blockquote>\n<p>Edit ~\/.bashrc to add an alias of &#8220;go&#8221; for the command &#8220;.\/start.sh&#8221; (see further below)<\/p>\n<blockquote><p>alias go=\u2019.\/start.sh\u2019<\/p><\/blockquote>\n<p>Test (need to logout and back in to read bash profile again):<\/p>\n<blockquote><p>[root@shimla ~]# go<br \/>\nStarting dhcpd:                                            [  OK  ]<br \/>\nUsing config file &#8220;.\/Elastix-PBX&#8221;.<br \/>\nStarted domain Elastix-PBX<br \/>\n[root@shimla ~]#<\/p><\/blockquote>\n<p><strong>Linux startup files explained:<\/strong><br \/>\nThese 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:<\/p>\n<p><em><strong>\/etc\/profile<\/strong><\/em><\/p>\n<p>These are systemwide defaults, mostly setting the environment (all Bourne-type shells, not just Bash)<\/p>\n<p><em><strong>\/etc\/bashrc<\/strong><\/em><\/p>\n<p>These are systemwide functions and aliases for Bash<\/p>\n<p><em><strong>$HOME\/.bash_profile<\/strong><\/em><\/p>\n<p>These are user-specific Bash environmental default settings, found in each user&#8217;s home directory (the local counterpart to \/etc\/profile)<\/p>\n<p><em><strong><br \/>\n$HOME\/.bashrc<\/strong><\/em><\/p>\n<p>These are user-specific Bash init file, found in each user&#8217;s home directory (the local counterpart to \/etc\/bashrc). Only interactive shells and user scripts read this file.<\/p>\n<p>Here are the contents of my startup files.<\/p>\n<blockquote><p>[root@shimla init.d]# cat ~\/.bashrc<br \/>\n# .bashrc<\/p>\n<p># User specific aliases and functions with &#8220;start.sh&#8221; alias (&#8220;go&#8221;) added:<\/p>\n<p>alias rm=&#8217;rm -i&#8217;<br \/>\nalias cp=&#8217;cp -i&#8217;<br \/>\nalias mv=&#8217;mv -i&#8217;<br \/>\nalias go=&#8217;.\/start.sh&#8217;<\/p>\n<p># Source global definitions<br \/>\nif [ -f \/etc\/bashrc ]; then<br \/>\n. \/etc\/bashrc<br \/>\nfi<br \/>\n[root@shimla init.d]#<\/p><\/blockquote>\n<blockquote><p>[root@shimla init.d]# cat ~\/.bash_profile<br \/>\n# .bash_profile<\/p>\n<p># Get the aliases and functions<br \/>\nif [ -f ~\/.bashrc ]; then<br \/>\n. ~\/.bashrc<br \/>\nfi<\/p>\n<p># User specific environment and startup programs<\/p>\n<p>PATH=$PATH:$HOME\/bin:\/usr\/sbin:\/sbin<\/p>\n<p>export PATH<br \/>\nunset USERNAME<br \/>\n[root@shimla init.d]#<\/p><\/blockquote>\n<p>Linux logout files:<\/p>\n<p>$HOME\/.bash_logout<br \/>\nThese are user-specific instruction file, found in each user&#8217;s home directory. Upon exit from a login (Bash) shell, the commands in this file execute.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 start.sh #!\/bin\/bash \/etc\/init.d\/dhcpd start cd \/etc\/xen xm create Elastix-PBX [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1395,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1433"}],"collection":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1433"}],"version-history":[{"count":4,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1433\/revisions"}],"predecessor-version":[{"id":1457,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1433\/revisions\/1457"}],"up":[{"embeddable":true,"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=\/wp\/v2\/pages\/1395"}],"wp:attachment":[{"href":"http:\/\/darenmatthews.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1433"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}