160 likes | 292 Views
Sydney Oracle Meetup. Shellfish Shells for Distinguished DBAs!. Agenda. What are they? Why you should care? Why I will talk about BASH only Learning BASH Readline Set The Good, The Bad and The Ugly Focus is on BASH only External commands won’t be covered. Built-ins will.
E N D
Sydney Oracle Meetup Shellfish Shells for Distinguished DBAs!
Agenda • What are they? • Why you should care? • Why I will talk about BASH only • Learning BASH • Readline • Set • The Good, The Bad and The Ugly • Focus is on BASH only • External commands won’t be covered. Built-ins will. • Won’t be talking about whiz bang custom functions. • Presentation is for Oracle DBA’s familiar with Shells already.
What are they? • Interactive User Interface into an Operating System. • Exist for all Major Operating Systems. • GUI Shells: • Gnome • KDE • Windowsexi • Command Line Shells: • Bourne (sh) • Korn (ksh) • C (csh) • Tcsh (tcsh) • Bourne Again (bash) • Powershell • And more...
Why you should care? • Are lightweight compared to GUIs. • Allow a high level of control. • Today’s implementations are opensourceand similar across OS. • Easy to program and automate repetitive tasks. • Good knowledge of shell scripting means you can think more and work less!
Why I will talk about bash only • Default Shell for many modern Operating Systems. • Ongoing development - still supported. • Most (not all of course) Oracle DBAs will use this Shell on a UNIX OS. • Time.
How to learn Bash? • Login to a shell and type “man bash” • Look at sample code. • Automate your everyday tasks. • Go to the Gnu BASH website - http://www.gnu.org/s/bash/
Useful readline settings • Custom settings stored in ~/.inputrc • set horizontal-scroll-mode=on • set completion-ignore-case=on • set mark-symlinked-directories=on • set show-all-if-ambiguous=on • set visible-stats=on
Readline commands • CTRL-R / CTRL-S search history • CTRL-A / CTRL-E move to beginning / end of a line • CTRL-L to clear screen • ESC-B / ESC-F move backwards and forwards between words • CTRL-X + CTRL-E edit the command in your EDITOR (good for long commands) • ESC-{ expand all filenames and encapsulate in brackets
set • set dump environment • set –e exit immediately (or go to trap handler) if any command fails • set –u error raised if variable accessed and not declared • set –x echo every command (better than set –v) • set –C does not clobber redirected files. • Can “set” by using set, shebang or bash
Good habits • Use declarations like program code • declare –a • declare –ror readonly • declare –i • declare –x or export • Combine where appropriate • function • local
Good habits • Use bash built-ins where appropriate • Use trap handlers • To cleanup after yourself • To perform extra DEBUGing • Use “\” to break up large lines in your BASH scripts. • Have a simple prompt that includes only the essentials. • unset variables no longer in use. • Use [[ ]] and (( )) where appropriate
Good habits • Bash is evolving - never stop learning!
Bad Habits • Setting TERM – let it be discovered where possible • Setting STTY ERASE - Set your terminal client properly • Overly complicated prompts - we don’t need to know the time. • Use $() instead of ticks ` `
Ugly Habits • .profile .bash_profile .bashrc use • Sourcing oraenvon login • Hardcoding ORACLE_BASE or ORACLE_HOME • Hardcoding PATH, LD_LIBRARY_PATH, CLASSPATH, LIBPATH etc with references to Oracle Homes • Setting ORA_NLS parameters • Alternatives: • Write a script to quickly discover, set, ask for your Oracle Home. • Looping and shifting through $[1..9] instead of getopts
Oft forgotten built-ins • cd – to revert back to flip back to the old directory • eval go Noons! • let do arithmetic the easy way • printf echo with more control
More Information • man bash • Advanced Bash Scripting Guide: http://tldp.org/LDP/abs/html/ • Gnu BASH source code:http://www.gnu.org/s/bash/ • Sample Code:Check Google • Learn SSH • Learn VIM