A Simple Shell Script Example

January 30, 2019 | By

A Simple Shell Script Example

shell script exampleCombining various command options can lead to hideously complex commands. If you are loath to type such long-winded commands on a regular basis, Unix and Linux offer the shell script option, which merits a brief detour. Here is you can find out the simple practical approach of shell script. You can readily see ps command; say so that ps perform a complex command with less typing effect.

Using ps command you can get a result of Oracle processes with the instance name.

Ps –ef | grep smon| grep –v grep

The output comes with all running smon processes of Oracle instances. If you create a file with name “trap_smon” or something else and write down these all commands in the same file. It is called a shell script because it contains all shell commands.

Vi trap_smon

Ps –ef|grep smon| grep –v grep

After saving above trap_smon file, you can execute using command sh trap_smon and get the output of same at any time. You can schedule it too using crontab utility of Unix and Linux. If you don’t want to execute using “sh trap_smon” then you need to make it executable. After changing the permission of shell script, you can able to make it executable as following.

Chmod +x trap_smon


The u+x option in chmod gives you alone permission to execute, as the owner. If you want to grant all users permission to use trap_smon, you would vary the chmod option as follows

Chmod a+x trap_smon


Chmod +x trap_smon

If you want to provide permission to your group only then you can use g+x with change permission command as following.

Chmod g+x trap_smon

After using chmod, you should run ls –l trap_smon to check that it has correct x fields for your purposes.

Shell scripts are available for all shells like Bourne, Korne, C shells, although the syntax and available features are different. Peculiar to the C shell, though, is another keystroke-saving ploy called the alias command.

Tags: , , , , ,

Category: shell script

Comments are closed.