Executable of the host type written in shell scripts

Source: Internet
Author: User

Recently, I am working on a project, because some functions are implemented using ORACLE package, but it is very good to use UNIX scripts, therefore, an executable host request is mounted on the AP to solve this problem.

I think this is a little interesting, so I share some basic things I have learned.

First, there must be a shell script file that can be executed under UNIX, and the file must be placed in the bin directory of the corresponding Application. For example, if you want to put the request under GL, the corresponding directory is

$ GL_TOP/$ APPLBIN/

In addition, make sure that the REQUEST executor has the execute permission on the file. For example, in the development environment, if the file is placed under DEV2, The DEV2AP user must have the execute permission on the file.

The process of hanging a request is the same as that of hanging a common request.

The focus is on this shell script. Note that this file must conform to the UNIX shell script format. In addition, it is recommended to write a script in a UNIX environment, because the line breaks in windows are different from those in UNIX.

The request parameters read by the script are read in the "$1" way. For parameter passing, the user guide says $1-$4 is a set system parameter, and the USER-defined parameter needs to start from $5. However, I actually tested DEV2 and DEV4, but I found that this is not the case.

When passing the parameter, executable of the HOST type places all the parameters in a string and passes them to parameter 1. The system parameter is in front of the custom parameter, regardless of the parameter type, the system always adds double quotation marks on both sides of the parameter value and uses spaces to separate parameters.

For example, I enter three string parameters:

"Test1", "test2", "test3"

Then, a string is obtained from $1:

XXGLCONVERTFILE FCP_REQID = 2303143 FCP_LOGIN = "<USERID>/<PWD>"

FCP_USERID = 1047 FCP_USERNAME = "<USERNAME>" FCP_PRINTER = "noprint"

FCP_SAVE_OUT = Y FCP_NUM_COPIES = 0"Test1" "test2" "test3"

As you can see, apart from the first SHELL script NAME, the system parameters are all a series of parameter (NAME = VALUE) pairs, and the last one is generally FCP_NUM_COPIES, and the VALUE is a number, then we define the parameters. Therefore, we can read our own parameters based on the characteristics of this string.

There is a powerful editing tool SED in UNIX. We can use this command to obtain the parameter value.

For details about how to use the SED command, refer to relevant information.

First, we read $1 and cut off the system parameters, and remove the double quotation marks added to both sides of the custom parameters.

Args = 'echo $1 | sed "s/^. * FCP_NUM_COPIES = [0-9] **" // "| sed" s/"// g "'

Note that "s" represents the replacement character. The source character and the target character are separated:

Sed "s/source/destination /"

After processing the preceding string, the following string is:

test1 test2 test3

Next, we can continue to use the sed command to intercept each parameter value:

Arg1 = 'echo $ args | sed "s /.*//"'

Arg2 = 'echo $ args | sed "s/$ arg1 //" | sed "s /.*//"'

Arg3 = 'echo $ args | sed "s/$ arg1 $ arg2 //" | sed "s /.*//"'

After obtaining the parameter values, we can make full use of our skills to process them,

Args = 'echo $1 | sed "s/^. * FCP_NUM_COPIES = [0-9] **" // "| sed" s/"// g "'

Echo "args:" $ args

Arg1 = 'echo $ args | sed "s /.*//"'

Echo "arg1:" $ arg1

Arg2 = 'echo $ args | sed "s/$ arg1 //" | sed "s /.*//"'

Echo "arg2:" $ arg2

Arg3 = 'echo $ args | sed "s/$ arg1 $ arg2 //" | sed "s /.*//"'

Echo "arg3:" $ arg3

If you enter "test1", "test2", "test3", the results of the above program are as follows:

args: test1 test2 test3
arg1: test1
arg2: test2
arg3: test3

Of course, the above Code is only applicable to relatively simple cases. For example, if there is a space or slash in the parameter value, you must consider it separately. However, the sed command is quite powerful and can be used in combination with regular expressions, it is generally not a problem.

If you want to exit the execution, you can directly use "exit" followed by a number to exit the Code. If it is not added, the system defaults to 0, indicating that the code is successful, A number other than 0 indicates failure (I have not found how to return the warning ).

 

Http://wolfyuan.itpub.net/post/25778/280094

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.