Ibm midrange IBMI Iseries v7r3-如何连接脚本以发送命令并获取输出
是否有一种方法可以编写一个脚本(python或java),该脚本可以连接到IBMi来运行命令并获得输出,或者可以是linux中的shell脚本(.sh)。例如,为了查看对象的授权值,我将在绿色屏幕中运行WRKOBJ[OBJNAME]和5以显示每个库的信息 我在这里的挑战是我需要获得几百个对象的值,所以我想如果有一个脚本,我可以自动处理这个过程并将值输出到一个文件中Ibm midrange IBMI Iseries v7r3-如何连接脚本以发送命令并获取输出,ibm-midrange,Ibm Midrange,是否有一种方法可以编写一个脚本(python或java),该脚本可以连接到IBMi来运行命令并获得输出,或者可以是linux中的shell脚本(.sh)。例如,为了查看对象的授权值,我将在绿色屏幕中运行WRKOBJ[OBJNAME]和5以显示每个库的信息 我在这里的挑战是我需要获得几百个对象的值,所以我想如果有一个脚本,我可以自动处理这个过程并将值输出到一个文件中 非常感谢您的建议和推荐。谢谢。sql提供了一些视图和表函数。这称为IBMi服务。 我想你可以从他们那里得到你想要的大部分信息 检查一
非常感谢您的建议和推荐。谢谢。sql提供了一些视图和表函数。这称为IBMi服务。 我想你可以从他们那里得到你想要的大部分信息
检查一些视图和表函数可用于sql。这称为IBMi服务。 我想你可以从他们那里得到你想要的大部分信息
检查是否可以在IBM i上运行PHP?下面是一个执行以下操作的PHP脚本:
- 从
,查询字符串中读取3个参数<代码>对象名
,objLib
objType
- 调用
运行qcmdexc
命令,输出到库DSPOBJAUT
中的QTEMP
OUTFILE
- 使用SQL
语句读取select
outfile的内容DSPOBJAUT
- 运行
以将输出文件内容作为json\u encode
流回显给web调用者json
您能在IBMi上运行PHP吗?下面是一个执行以下操作的PHP脚本:
- 从
查询字符串中读取3个参数<代码>对象名
,objLib
,objType
- 调用
qcmdexc
运行DSPOBJAUT
命令,输出到库QTEMP
中的OUTFILE
- 使用SQL
select
语句读取DSPOBJAUT
outfile的内容
- 运行
json\u encode
以将输出文件内容作为json
流回显给web调用者
我已经看过了文档,看起来不错。您是否有关于如何/在何处执行查询的参考资料?我是IBMi新手,所以我不知道如何执行查询。我知道你没有PHP,所以也许用java可以找到linux ODBC驱动程序,你只需要ACS linux App Pkg,我已经阅读了文档,看起来不错。您是否有关于如何/在何处执行查询的参考资料?我是IBMi的新手,所以不知道如何执行查询。我知道你没有PHP,所以也许用java可以找到一个linux ODBC驱动程序,你只需要ACS linux应用程序包谢谢你的帮助,因为现在我的机器上没有PHP,但我会注意这一点。谢谢。谢谢你的帮助,因为现在我的机器里没有PHP,但我会注意这一点。感谢
<?php
// set out document type to text/javascript instead of text/html
header("Content-type: text/javascript; charset:utf-8;");
$objName = isset($_GET["objName"]) ? $_GET["objName"]: '' ;
$objLib = isset($_GET["objLib"]) ? $_GET["objLib"]: '' ;
$objType = isset($_GET["objType"]) ? $_GET["objType"]: '' ;
// connect to ibm i
$libl = 'qgpl qtemp' ;
$options = array('i5_naming' => DB2_I5_NAMING_ON);
$options['i5_libl'] = $libl ; // library names separated by space.
$conn = db2_connect("*LOCAL","","", $options);
if (!$conn)
{
echo db2_conn_errormsg() ;
}
// build and run dspobjaut command. Will output object authorities to file in qtemp.
$cmds = 'dspobjaut obj(' . $objLib . '/' . $objName . ') objtype(' . $objType . ') output(*outfile) outfile(qtemp/objaut)';
$sql = "call qcmdexc('" . $cmds . "', " . strlen($cmds) . ")" ;
$stmt = db2_prepare( $conn, $sql ) ;
$result = db2_execute( $stmt ) ;
// read contents of dspobjaut outfile. Read into array where each item
// contains object. Each property of object is column from the dspobjaut outfile table.
$sql = 'select a.* from qtemp/objaut a ' ;
$stmt = db2_prepare( $conn, $sql ) ;
$result = db2_execute( $stmt ) ;
$ar1 = db2Stmt_ToManyRowArray($stmt) ;
// return dspobjaut output as json data stream.
$encode_txt = json_encode( $ar1, JSON_UNESCAPED_UNICODE ) ;
echo $encode_txt ;
// --------------------- db2Stmt_GetColNames ----------------
// build and return array of column names from a db2_execute
// executed $stmt.
function db2Stmt_GetColNames( $stmt )
{
$colCx = db2_num_fields($stmt);
$colNames = array( ) ;
for( $ix=0; $ix < $colCx; $ix++ )
{
array_push( $colNames, db2_field_name( $stmt, $ix )) ;
}
return $colNames ;
}
// ------------------- db2Stmt_ToManyRowArray ------------
function db2Stmt_ToManyRowArray( $stmt )
{
$colNames = db2Stmt_GetColNames( $stmt ) ;
$manyArr = array( ) ;
while( $row = db2_fetch_array( $stmt ))
{
// build row array consisting of column name/vlu pairs for
// each column of the result set.
$rowArr = array( ) ;
for( $ix = 0 ; $ix < count($colNames) ; $ix++ )
{
$rowArr[ $colNames[$ix] ] = rtrim($row[$ix]) ;
}
// push the $rowArr onto the array of many rows.
$manyArr[] = $rowArr ;
}
return $manyArr ;
}
?>