Oracle Shell Scripting: First Review on Amazon.com

Last week my book, Oracle Shell Scripting: Linux and UNIX Programming for Oracle got its first review on Amazon.com:

Here’s Mike Bennett’s complete review from Amazon:

I’m a veteran Oracle Database Administrator and most of my work is on Unix systems so I wasn’t sure how much information in this book would be useful to me. I was pleasantly surprised to find what a wide range of scripting tips and techniques this manual provides. I was impressed by the fact that the author didn’t just describe HOW to do something, but also explained WHY a particular approach was taken. I also like the fact that the scripts given aren’t just contrived samples, but are practical and useful as given. This information will definitely help simplify some of my routine tasks and provide me with timely information about the environments and systems I work with. The author also pointed out how to go beyond what was provided in the book by suggesting ways the examples might be modified. I’ve already taken advantage of that with a script I helped one of my clients develop.

Thanks to Mike for the great review! I’m glad he found the book useful and I hope others do as well. If you have my book I welcome your feedback and encourage you to post your own review on Amazon!

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


When to use shell scripts

With my new book “Oracle Shell Scripting” now on shelves you may be wondering what shell scripting can do for you. Below is an excerpt from the book that touches on when you may want to think about scripting. While the book is geared toward Oracle users much of the content would apply to shell scripting regardless of the use.

When to script

A shell script can be written to do anything you would do at the command line. So when do you want to write a shell script? When is it a bad idea? Well, here are a few guidelines I use.

Shell scripts can yield the biggest return on regular tasks that are performed more-or-less the same way each time. If every day you log into a system and remove some files out of a directory, backup a database or check a log file for a specific string of characters you should automate these tasks. Chances are you can make them run automatically and save yourself the hassle all together.

Shell scripts aren’t just for automation though. In some cases a script saves us time in a different way by allowing us to run a simple command instead of a very complicated one.

One of the most powerful features of the shell and shell scripting is the ability to affect several files and even multiple servers with a single script. Loops and commands like find make shell scripting ideal for managing large numbers of files in a single step.

In general there is little point in writing a shell script to do something once. The exception to this is occasionally something needs to be run at a time when you would rather not have to be around to run it yourself. In this case you may decide to bundle those commands into a shell script and schedule it to run without you involved. Be careful with this type of script and always be thinking “what if something goes wrong?” because sooner or later it will and if you’re not around to fix it you could get in some hot water.

Oracle Shell ScriptingFor more information like this check out my book Oracle Shell Scripting, only $34.95 from Rampant TechPress.

Buy it now!


shell script, unix, linux, oracle, bash, scripting

Get rid of color ‘ls’ output in Linux

Color ls outputMany popular varieties of Linux use a “feature” which causes the ls command output to show files, directories, links, etc. all in different colors. I guess some people prefer this, but I find it at best annoying, and at worst illegible. Specifically the color-coding of symbolic links tend to show in such a light color that it is often impossible to read.

The color output is accomplished by adding the --color=tty or a similar option to the ls command. This is typically accomplished by creating an alias to ls in either the user’s profile or in one of the system-wide profiles.

alias ls='ls --color=tty'

My personal preference is to remove this line from any system-wide configuration files (such as /etc/profile) and allow users to set it in their own profile if preferred. If you don’t have the desire or ability to make this change universally than a user can easily disable the color output by using the unalias command:

unalias ls

This can either be added to the user’s configuration file (e.g. the .profile or .bash_profile in their home directory), or you can just type unalias ls anytime to disable color ls output for the rest of the current shell session. This can be especially useful to turn off the color output when you’re working on someone else’s system.

Color-coded ls output can cause permissions errors in some circumstances, so in my opinion it is best left off, but if you’re stuck with it then it’s nice to know how it can be disabled when necessary.

ls, sysadmin, system administration, linux, shell, bash, sh, UNIX

Setting Default Permissions Using a File Mask

By default, Linux and UNIX permissions for new directories are typically set to 755 allowing read, write, and execute permissions to user and only read and execute to group and other users. Conversely, file permissions default to 644 allowing read and write access to user but only read to group and others. These defaults are controlled by the user file-creation mask or umask.

A user or administrator may want to change the Linux default permissions by using the umask command in a login script. The umask command can be used without specifying any arguments to determine what the current default permissions are. The value displayed by umask must be subtracted from the defaults of 777 for directories and 666 for files to determine the current defaults. A typical umask which will generate the permissions listed in the previous paragraph would be 0022. The first digit pertains to the sticky bit which will be explained further later.

The –S option can be used to see the current default permissions displayed in the alpha symbolic format. Default permissions can be changed by specifying the mode argument to umask within the user’s shell profile (.bash_profile for the bash) script.

The following are some examples.

Using umask to Set Default Permissions

$ umask
0022

$ umask -S
u=rwx,g=rx,o=rx

$ umask 033

$ umask
0033

$ umask -S
u=rwx,g=r,o=r

The default umask will cause users to create files which any user can read. In many instances where you have a multi-user system this is not desirable and a more appropriate umask may be 077. That umask will enforce the default permissions to be read, write and execute for the owner and no permissions for the group and other users.

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


unix, linux, umask, shell, bash, sysadmin, system administration

Preventing Accidental File Deletion in Linux and UNIX

A little trick that some Linux users like to implement to prevent accidental file deletion is via the use of an alias. Aliases are similar to variables and can either be set in a session or by placing the alias command in the .profile or .bash_profile file with a text editor.

By adding this alias the user will be prompted to confirm each file before it is deleted; otherwise Linux, unlike Microsoft Windows, will delete whatever files match the filename criteria without warning!

$ alias rm='rm -i'
$ touch touch1.fil touch2.fil touch3.fil
$ rm touch*
rm: remove regular empty file `touch1.fil'? y
rm: remove regular empty file `touch2.fil'? y
rm: remove regular empty file `touch3.fil'? y

Easy Linux CommandsFor more tips like this check out my book Easy Linux Commands, only $19.95 from Rampant TechPress.

Buy it now!


linux, unix, system administration, sysadmin, bash