python自动化一些EBS的步骤

对于存在交互过程的远程访问,如ssh, ftp, mencoder, passwd等,通过Pexpect模块可以根据应用的输出控制交互过程,从而提高容错性。

Pexpect模块首先通过生成子应用以代理交互应用,这样就可以通过检测子应用的模式匹配情况以响应交互应用的输出。

Python也有其他的类Expect模块,但是这些模块往往依赖于TCL和Expect扩展模块,或编译时依赖于C扩展模块。而Pexpect模块除了基于Python标准库中的pty模块之外,完全独立。从Pexpect 4.0开始,Pexpect模块可运行于Windows系统和POSIX系统。当然,由于pexpect.spawn()和pexpect.run()依赖于Python标准库中的pty模块,而pty模块只在POSIX系统中存在,所以Windows系统上的功能有限。

Pexpect模块的安装:
Python 3.3或Python 2.7以上
pip install pexpect

---------------------------------------------------------------------------------

模拟adadmin输入,adadmin工具输入例子如下:

[appl@ebstest ~]$ adadmin

Copyright (c) 2002 Oracle Corporation
Redwood Shores, California, USA
Oracle Applications AD Administration
Version 12.0.0

NOTE: You may not use this utility for custom development
unless you have written permission from Oracle Corporation.

Your default directory is '/data1/test/app/apps/apps_st/appl'.
Is this the correct APPL_TOP [Yes] ? ----------------------------------------需要输入

AD Administration records your AD Administration session in a text file
you specify. Enter your AD Administration log file name or press [Return]
to accept the default file name shown in brackets.

Filename [adadmin.log] : ----------------------------------------------------需要输入

************* Start of AD Administration session *************
AD Administration version: 12.0.0
AD Administration started at: Sun Jun 28 2020 09:02:35

APPL_TOP is set to /data1/test/app/apps/apps_st/appl

You can be notified by email if a failure occurs.
Do you wish to activate this feature [No] ? --------------------------------需要输入

Please enter the batchsize [1000] : -----------------------------------------需要输入

Please enter the name of the Oracle Applications System that this
APPL_TOP belongs to.

The Applications System name must be unique across all Oracle
Applications Systems at your site, must be from 1 to 30 characters
long, may only contain alphanumeric and underscore characters,
and must start with a letter.

Sample Applications System names are: "prod", "test", "demo" and
"Development_2".

Applications System Name [test] : test *


NOTE: If you do not currently have certain types of files installed
in this APPL_TOP, you may not be able to perform certain tasks.

…………………………略

Please enter the name Oracle Applications will use to identify this APPL_TOP.

The APPL_TOP name you select must be unique within an Oracle Applications
System, must be from 1 to 30 characters long, may only contain
alphanumeric and underscore characters, and must start with a letter.

Sample APPL_TOP Names are: "prod_all", "demo3_forms2", and "forms1".

APPL_TOP Name [ebstest] : ebstest *


You are about to use or modify Oracle Applications product tables
in your ORACLE database 'test162'
using ORACLE executables in '/data1/test/app/apps/tech_st/10.1.2'.

Is this the correct database [Yes] ? ---------------------------------------------------------------------------需要输入

AD Administration needs the password for your 'SYSTEM' ORACLE schema
in order to determine your installation configuration.

Enter the password for your 'SYSTEM' ORACLE schema: -----------------------------------------------------------需要输入

The ORACLE username specified below for Application Object Library
uniquely identifies your existing product group: APPLSYS

Enter the ORACLE password of Application Object Library [APPS] : ---------------------------------------------需要输入

AD Administration is verifying your username/password.

The status of various features in this run of AD Administration is:

<-Feature version in->
Feature Active? APPLTOP Data model Flags
------------------------------ ------- -------- ----------- -----------
CHECKFILE Yes 1 1 Y N N Y N Y
PREREQ Yes 6 6 Y N N Y N Y
CONCURRENT_SESSIONS No 2 2 Y Y N Y Y N

Identifier for the current session is 36773

Reading product information from file...

Reading language and territory information from file...

Reading language information from applUS.txt ...

AD Administration warning:
Product Data File
/data1/test/app/apps/apps_st/appl/admin/zfaprod.txt
does not exist for product "zfa".
This product is registered in the database but the
above file does not exist in APPL_TOP. The product
will be ignored without error.

…………………………略

Reading database to see what industry is currently installed.

Reading FND_LANGUAGES to see what is currently installed.
Currently, the following languages are installed:

Code Language Status
---- --------------------------------------- ---------
US American English Base
ZHS Simplified Chinese Install

Reading language information from applZHS.txt ...

Your base language will be AMERICAN.

Your other languages to install are: SIMPLIFIED CHINESE

Setting up module information.
Reading database for information about the modules.
Saving module information.
Reading database for information about the products.
Reading database for information about how products depend on each other.
Reading topfile.txt ...

Saving product information.

AD code level : [B.4]

AD Administration Main Menu
--------------------------------------------------

1. Generate Applications Files menu

2. Maintain Applications Files menu

3. Compile/Reload Applications Database Entities menu

4. Maintain Applications Database Entities menu

5. Change Maintenance Mode

6. Exit AD Administration

Enter your choice [6] :-----------------------------------------需要输入

-----------脚本内容----------------------------------------------------------------------------

vi pyadadmin.py

import pexpect,sys
child=pexpect.spawn('adadmin')
child.logfile=sys.stdout


child.expect('correct APPL_TOP')
child.sendline('')    ----------------------------默认为回车
child.expect('adadmin.log')
child.sendline('adadmin.log')
child.expect('activate this feature')
child.sendline('No')
child.expect('enter the batchsize')
child.sendline('1000')
child.expect('correct database')
child.sendline('Yes')
child.expect('Enter the password for your \'SYSTEM\'')
child.sendline('123456')
child.expect('Enter the ORACLE password of Application Object')
child.sendline('123456')
child.expect('Enter your choice \[6\]')
child.sendline('6')

--------------------------------------------------------------------------------

python  pyadadmin.py

同理克隆配置也可以通过pexpect进行自动输入。

猜你喜欢

转载自www.cnblogs.com/wangchuangyunhai/p/13208312.html