Basic File Navigation
The "pwd" command displays the current directory.
The "ls" command lists all files and directories in the specified directory. If no location is defined it acts on the current directory.
The "-a" flag lists hidden "." files. The "-l" flag lists file details.
The "cd" command is used to change directories.
The "touch" command is used to create a new empty file with the default permissions.
The "rm" command is used to delete files and directories.
The "-R" flag tells the command to recurse through subdirectories.
The "mv" command is used to move or rename files and directories.
The "." represents the current directory.
The "cp" command is used to copy files and directories.
The "mkdir" command is used to create new directories.
The "rmdir" command is used to delete directories.
The "find" command can be used to find the location of specific files.
The "/" flag represents the staring directory for the search. Wildcards such as "dbms*" can be used for the filename.
The "which" command can be used to find the location of an executable you are using.
The "which" command searches your PATH setting for occurrences of the specified executable.
The "umask" command can be used to read or set default file permissions for the current user.
The umask value is subtracted from the default permissions (666) to give the final permission.
The "chmod" command is used to alter file permissions after the file has been created.
Character eqivalents can be used in the chmod command.
The "chown" command is used to reset the ownership of files after creation.
The "-R" flag causes the command ro recurse through any subdirectories.
OS Users Management
The "useradd" command is used to add OS users.
- The "-G" flag specifies the primary group.
- The "-g" flag specifies the secondary group.
- The "-d" flag specifies the default directory.
- The "-m" flag creates the default directory.
- The "-s" flag specifies the default shell.
The "usermod" command is used to modify the user settings after a user has been created.
The "userdel" command is used to delete existing users.
The "-r" flag removes the default directory.
The "passwd" command is used to set, or reset, the users login password.
The "who" command can be used to list all users who have OS connections.
- The "head -5" command restricts the output to the first 5 lines of the who command.
- The "tail -5" command restricts the output to the last 5 lines of the who command.
- The "grep -i ora" command restricts the output to lines containing "ora".
- The "wc -l" command returns the number of lines from "who", and hence the number of connected users.
The "ps" command lists current process information.
Specific processes can be killed by specifying the process id in the kill command.
uname and hostname
The "uname" and "hostname" commands can be used to get information about the host.
Error Lines in Files
You can return the error lines in a file using.
The "grep -i ORA-" command limits the output to lines containing "ORA-". The "-i" flag makes the comparison case insensitive. A count of the error lines can be returned using the "wc" command. This normally give a word count, but the "-l" flag alteres it to give a line count.
Remove Old Files
findcommand can be used to supply a list of files to the
rmcommand or the "-delete" command can be used directly.
File Exists Check
The Bash shell allows you to check for the presence of a file using the "[ -e filepath ]" comparison. In the following script a backup log is renamed if it is present and files older than 30 days are deleted are deleted.
This is one example of a log rotation, where the most current log doesn't include the date in it's name.
Rotate Log Files
See the previous section for another variant on log rotation.
The following script provides an example of how to manage a log rotation using the Bash shell. The log file includes the date in the file name. Files older than 30 days are deleted.
Perform Action for Every File in a Directory
The following scripts shows two methods for performing an action for each file in a directory.
Perform Action for Every Line in a File
The following scripts shows a method for performing an action for each line in a file.
An alias is a named shortcut for a longer command using the following format.
For example, if you require sudo access for a specific command, you might want to include this as an alias so you don't have to remember to type it.
Remove DOS CR/LFs (^M)
Remove DOS style CR/LF characters (^M) from UNIX files using.
The newly created tempfile should have the ^M character removed.
Where available, it is probably better to use the
Run Commands As Oracle User From Root
The following scripts shows how a number of commands can be run as the "oracle" user the "root" user.
This is often necessary where CRON jobs are run from the root user rather than the oracle user.
In order to save space on the filesystem you may wish to compress files such as archived redo logs. This can be using either the
gzipcommand results in a compressed copy of the original file with a ".gz" extension. The
gunzipcommand reverses this process.
compresscommand results in a compressed copy of the original file with a ".Z" extension. The
uncompresscommand reverses this process.
Reports virtual memory statistics.
Reports the current memory usage. The "-/+ buffers/cache:" line represents the true used and free memory, ignoring the Linux file system cache.
Reports I/O statistics.
On Linux systems sar (System Activity Reporter) is probably one of the simplest and most versatile tools for reporting system utilization including CPU, memory, disk and network activity. It automatically collects system activity statistics when installed using the following command.
The sar command syntax takes the following form.
The "options" parameters determine what is reported, which will be discussed later. The "interval" parameter indicates the time interval in seconds between samples. The "count" parameter indicates the number of samples that will be taken before the command ends. If "count" is omitted, the sampling will continue indefinitely. If both "interval" and "count" are omitted, the command will report the values from the 10 minute samples taken since the machine was last restarted.
- Basic CPU: sar [-u] [interval [count]]
- Load Average: sar -q [interval [count]]
- Kernel Paging: sar -B [interval [count]]
- Unused Memory: sar -r [interval [count]]
- Swap Space: sar -S [interval [count]]
- Average Disk I/O: sar -b [interval [count]]
- Disk I/O: sar -dp [interval [count]]
- Network: sar -n DEV [interval [count]]
- Network Errors: sar -n EDEV [interval [count]]
Here is an example of the output from a CPU report.
Reports processor related statistics.
Displays top tasks.
The PID column can then be matched with the SPID column on the V$PROCESS view to provide more information on the process.
You may be required to use passwords in scripts calling Oracle tools, like SQL*Plus, Export/Import and RMAN etc. One method to remove the credentials from the script itself is to create a credentials file to hold them. In this case I'm using "/home/oracle/.scottcred", which contains the following.
Change the permissions to make sure the file is only visible to the owner.
Now replace references to the credentials with the contents of the file.
There are two methods of editing the crontab file. First you can use the "crontab -l > filename" option to list the contents and pipe this to a file. Once you've editied the file you can then apply it using the "crontab filename".
- Login as root
- crontab -l > newcron
- Edit newcron file.
- crontab newcron
Alternatively you can use the "crontab -e" option to edit the crontab file directly.
The entries have the following elements.
The first 5 fields can be specified using the following rules.
The following entry runs a cleanup script a 01:00 each Sunday. Any output or errors from the script are piped to /dev/null to prevent a buildup of mails to root.
Cluster Wide CRON Jobs On Tru64
On clustered systems cron is node-specific. If you need a job to fire once per cluster, rather than once per node you need an alternative approach to the standard cron job. One approach is put forward in the HP best practices document (Using cron in a TruCluster Server Cluster), but in my opinion a more elegant solution is proposed by Jason Orendorf of HP Tru64 Unix Enterprise Team (TruCluster Clustercron).
In his solution Jason creates a file called /bin/cronrun with the following contents.
This script returns TRUE (0) only on the node which is the CFS serving cluster_root.
All cluster wide jobs should have a crontab entry on each node of the cluster like.
Although the cron jobs fire on all nodes, the "/bin/cronrun &&" part of the entry prevents the script from running on all nodes except the current CFS serving cluster_root.
Here are some files that may be of use.
Group settings for users.
Hostname lookup information.
Kernel parameters for Solaris.
Kernel parameters for Tru64.
Kernel parameters for Linux.