{"id":1300,"date":"2016-03-17T09:25:53","date_gmt":"2016-03-17T07:25:53","guid":{"rendered":"http:\/\/www.ludovicocaldara.net\/dba\/?p=1300"},"modified":"2016-03-17T09:25:53","modified_gmt":"2016-03-17T07:25:53","slug":"bash-tips-2-smart-env-personal-accounts","status":"publish","type":"post","link":"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-2-smart-env-personal-accounts\/","title":{"rendered":"Bash tips &#038; tricks [ep. 2]: Have a smart environment for personal accounts"},"content":{"rendered":"<p>This is the second epidose of a <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-1-personal-accounts-permissions\/\">small series<\/a>.<\/p>\n<p><strong>Description:<\/strong><\/p>\n<p>The main technical account (oracle here) usually has the smart environment, with aliases, scripts avilable at fingertips, correct environment variables and functions.<\/p>\n<p>When working with personal accounts, it may be boring to set the new environment at each login, copy it from a golden copy or reinvent the wheel everytime.<\/p>\n<p><strong>BAD:<\/strong><\/p>\n<pre class=\"lang:sh decode:true\">Login: ludo\r\nPassword:\r\n\r\n-bash-4.1$  env\r\nHOSTNAME=testsrv\r\nTERM=xterm\r\nSHELL=\/bin\/bash\r\nSSH_CLIENT=w.x.y.z 65373 22\r\nOLDPWD=\/home\/ludo\r\nSSH_TTY=\/dev\/pts\/0\r\nUSER=ludo\r\nLS_COLORS=...\r\nMAIL=\/var\/spool\/mail\/ludo\r\nPATH=\/usr\/local\/bin:\/bin:\/usr\/bin:\/usr\/local\/sbin:\/usr\/sbin:\/sbin\r\nPWD=\/home\/ludo\r\nLANG=en_US.UTF-8\r\nHISTCONTROL=ignoredups\r\nSHLVL=1\r\nHOME=\/home\/ludo\r\nLOGNAME=ludo\r\nLESSOPEN=||\/usr\/bin\/lesspipe.sh %s\r\n_=\/bin\/env\r\n\r\n-bash-4.1$ typeset -f | grep '()'\r\n_module ()\r\n    COMPREPLY=();\r\n_module_avail ()\r\n_module_long_arg_list ()\r\n_module_not_yet_loaded ()\r\nmodule ()\r\n\r\n-bash-4.1$ vi .bash_profile\r\n... damn, let's make this environment smarter\r\n...<\/pre>\n<p>&nbsp;<\/p>\n<p><strong>GOOD:<\/strong><\/p>\n<p>Distribute a standard .bash_profile that calls a central profile script valid for all the users:<\/p>\n<pre class=\"lang:sh decode:true\"># [ ludo@testsrv:\/home\/ludo [15:53:18] [12.1.0.2 env:orcl12c] 0 ] #\r\n# cat .bash_profile\r\n# .bash_profile\r\n\r\n#################################################\r\n# WARNING: This script is controlled by puppet.\r\n# If you need to override or add something\r\n# please use ~\/.bash_profile_local\r\n#################################################\r\n\r\nif [ -f ~\/.bashrc ]; then\r\n    . ~\/.bashrc\r\nfi\r\n\r\n# load oracle common environment\r\n. \/u01\/app\/oracle\/scripts\/sbin\/ora_profile\r\n\r\n[ -f $HOME\/.bash_profile_local ] &amp;&amp; . $HOME\/.bash_profile_local\r\n\r\n# [ ludo@testsrv:\/home\/ludo [15:53:21] [12.1.0.2 env:orcl12c] 0 ] #\r\n#\r\n<\/pre>\n<p>Make your common environment as smart as possible. If any commands need to be run differently depending on the user (oracle or not oracle), just use a simple if:<\/p>\n<pre class=\"lang:sh decode:true\">if [ $USER != \"oracle\" ] ; then\r\n        alias vioratab='sudoedit -u oracle $ORATAB'\r\nelse\r\n        alias vioratab='vi $ORATAB'\r\nfi<\/pre>\n<p>The goal of course is to avoid as many types as you can, and let all your colleagues profit of the smart environment.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is the second epidose of a small series. Description: The main technical account (oracle here) usually has the smart environment, with aliases, scripts avilable at fingertips, correct environment variables and functions. When working with personal accounts, it may be &hellip; <a href=\"https:\/\/www.ludovicocaldara.net\/dba\/bash-tips-2-smart-env-personal-accounts\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,132],"tags":[],"class_list":["post-1300","post","type-post","status-publish","format-standard","hentry","category-linux","category-triblog"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1300","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/comments?post=1300"}],"version-history":[{"count":3,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1300\/revisions"}],"predecessor-version":[{"id":1320,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/posts\/1300\/revisions\/1320"}],"wp:attachment":[{"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/media?parent=1300"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/categories?post=1300"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ludovicocaldara.net\/dba\/wp-json\/wp\/v2\/tags?post=1300"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}