Database Reference
In-Depth Information
Nothing is as frustrating as a program that fails-out when it discovers a problem that it could easily be handled by
the script. For instance, if your script requires a specific directory for logs or staging then the script should create those
directories and set the proper permissions required by your program:
if [ ! -d /tmp/staging ]; then
mkdir -p /tmp/staging
chmod 770 /tmp/staging
fi
Hung program execution is another area in which your program should anticipate failures and test for problem
situations before they happen. For example, empty files can cause your script to hang, so before grepping file output,
you should check to see that the file truly exists:
if [ -f myFile.lst ]; then
cat myFile.lst | grep "Hello World"
else
echo "File myFile.lst is missing!"
exit 1
fi
There are several other relevant scripting guidelines in The Art of Unix Programming . The examples we just
considered are representative of the types of programming fundamentals omitted from this chapter in the interest of
brevity and clarity.
Passwords and Shell Scripts
Among all the guidelines and suggestions for shell programming there has always been one hard and fast rule:
Never hard-code passwords into your scripts—it can become a maintenance and security nightmare. It is up to you
to develop a method for managing your password files. The choice is yours whether you develop an in-house Java
solution, apply a technique you found on the web, depend on obfuscation and hidden files, or use some other bit of
cleverness. It is beyond the scope of this topic to suggest solutions.
The remainder of this chapter will use the variable named ${SECRET_PASSWORD} whenever a password is required
in the script.
Calling EM CLI from a Shell Script
Command-line utilities like SQL*Plus run in a subshell inside of shell scripts, wrapped in “Here Documents” that are
typically shown as opening and closing EOF tags, like this example shows:
sqlplus / as sysdba <<EOF
SELECT sysdate FROM dual;
exit
EOF
SYSDATE
---------
03-AUG-14
 
Search WWH ::




Custom Search