通过运行批处理命令进入OpenSSL的 [英] run commands into openssl through batch

查看:1232
本文介绍了通过运行批处理命令进入OpenSSL的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图建立在正常运行时间监控自定义脚本,并有此命令运行OpenSSL和有我传递到它运行参数。

 的OpenSSL的s_client.First -CAfile C:\\ apcerts \\证书\\ -quiet -connect $ {HOST}:$ {PORT}> $ {TMPF} 2  - ;&放大器1所述; EOF
< TF80DOC>< XPLN />< / TF80DOC>
EOF如果(选择字符串更新等级$ {} TMPF GT&;的/ dev / null的)
{
    exitstatus = $ STATE_OK
    选择字符串更新等级$ {TMPF} |排序| uniq的}
ELSEIF(选择字符串监管$ {} TMPF GT&;的/ dev / null的)
{
    exitstatus = $ STATE_OK
    选择字符串监管$ {TMPF} |排序| uniq的}
其他{
    回声`date`>> /tmp/caught_errs.out
    猫$ {TMPF}>> /tmp/caught_errs.out
    回声>> /tmp/caught_errs.out
    exitstatus = $ STATE_CRITICAL
    }
RM -f $ {} TMPF 2 - ;的/ dev / null的退出$ {} exitstatus

我想有变量$ {HOST}:$ {}口留空白,我想有我手动把信息参数和字段与该信息填充。

例如我需要连接到blank-xml.myinfo.com:30011。

我遇到的问题是,当我设置了对自定义监视器我有打开OpenSSL的,但不能打开.txt文件来运行特定命令的.BAT。

我需要做什么才能为这个工作做。

更新:

我已传递信息OpenSSL的是小了很多的批处理文件。

 关闭@echo
C:\\ OpenSSL的 - Win64的\\斌\\ OpenSSL的的s_client.First -connect help-xml.helpme.com:443

这部分的工作,需要在屏幕上精彩的表演信息。我需要另一个命令发送到窗口还却得到了一个错误,说明了在<命令不是可执行文件或批处理。

这命令是< TF80DOC>< XPLN />< / TF80DOC> 我已经使用&放审判;符号并用回声之前,但仍然我得到同样的错误,或者屏幕上会弹出并没有立即的信息关闭。

在if then语句的工作我运行后< TF80DOC>< XPLN />< / TF80DOC> ,因为这已经显示的报表信息正在对于。但是,如果我不能获得< TF80DOC>< XPLN />< / TF80DOC> 后发送到OpenSSL中的s_client.First -connect help-xml.helpme.com:443 然后运行if语句不会有任何效果。

更新:

我在的s_client.First -connect help-xml.helpme.com:443

改变了PowerShell命令在命令管道

新的code看起来像

  @'
< TF90DOC>< XPLN />< / TF90DOC>
@ | C:\\ OpenSSL的 - Win64的\\斌\\ OpenSSL的的s_client.First -quiet -connects_client -connect help-xml.helpme.com:443> test1.txt的2 - ;&放大器; 1

在if then语句是不是一个问题,因为我知道如何解决它的一部分。在code ++工程的PowerShell的一部分,但要求我preSS输入是不是我需要做的。我需要它,而无需用户输入时自动执行命令

有关批处理命令我已经为它的一些细微变化,这是

 关闭@echo
SETLOCAL enabledelayedexpansion
设置VAR =&所述; TF90DOC>&下; XPLN />&下; / TF90DOC>中回声回声!无功! | C:\\ OpenSSL的 - Win64的\\斌\\ OpenSSL的的s_client.First -connect tf90-xml.bsi.com:443> test1.txt的2 - ;&放大器; 1

此命令仍然给我的错误


  

<在这个时候意外。



解决方案

<击>试试这个:(见下面编辑)

 关闭@echo

    回声(^^^&LT; TF90DOC ^^^&GT; ^^^&LT; XPLN / ^^^&GT; ^^^&LT; / TF90DOC ^^^&GT;
    回声;
)| C:\\ OpenSSL的 - Win64的\\斌\\ OpenSSL的的s_client.First -connect tf90-xml.bsi.com:443&GT; test1.txt的2 - ;&放大器; 1

编辑:

从你的描述,这听起来像OpenSSL是没有准备好XML入境后立即投入,是黑洞的新行通过管道输送到标准输入。因此,而不是一下子倾倒一切标准输入,你需要引入某种形式的睡眠,并听取该程序的标准输出为相应的提示。

下面是概念的JScript中证明,我认为能尽快应用于你,因为我知道什么文字OpenSSL的使用提示输入XML,然后为<大骨节病>输入键preSS 。这是因为在 WSHScriptExec的StdOut所述的相似方法物业文档页面,并且比thusfar尝试任何解决方案更加灵活。

test.bat的

  @if(@a == @二)@end / *开始多行的JScript评论::批部分关闭@echo
SETLOCALCSCRIPT / NOLOGO / E:JScript的%〜F0GOTO:EOF::年底批量部分/开始的JScript * /
VAR OSH =新的ActiveXObject('wscript.shell'),
    FSO =新的ActiveXObject(Scripting.FileSystemObject的),
    登录= fso.CreateTextFile('output.txt的',真)
    读;VAR EXE = osh.Exec(CMD / C test2.bat');而(1){
    如果(!exe.StdOut.AtEndOfStream){
        读+ = exe.StdOut.Read(1); //读取1字符在一个时间
        如果(/精氨酸1:/测试(读)){
            WSH.Sleep(50);
            exe.StdIn.Write('&LT; TF80DOC&GT;&LT; XPLN /&GT;&LT; / TF80DOC&GT; \\ n');
            WSH.Sleep(100);            //这是我们要拍摄的输出。
            读= exe.StdOut.ReadLine();
            WSH.Echo(读);
            log.WriteLine(读);            读='';
        }否则如果(/ preSS任意键/ .TEST(读)){
            WSH.Sleep(100);
            exe.StdIn.Write('\\ n');
            打破;
        }
    }
    别的WSH.Sleep(100);
}
log.Close();而(exe.Status!)WSH.Sleep(100);
WSH.Echo('完成');

test2.bat

 关闭@echo
SETLOCAL enabledelayedexpansion集/ P输入=精氨酸1:回声(输入:输入!暂停

i am trying to set up a custom script in uptime monitoring and have this command run openssl and have arguments that i pass into it run.

openssl s_client -CAfile C:\apcerts\certs\ -quiet -connect ${HOST}:${PORT} > ${TMPF} 2>&1 < EOF
<TF80DOC><XPLN/></TF80DOC>
EOF

if (Select-String "Update Level" ${TMPF} > /dev/null)
{
    exitstatus=$STATE_OK
    Select-String "Update Level" ${TMPF} | sort | uniq}
elseif (Select-String "Regulatory" ${TMPF} > /dev/null)
{
    exitstatus=$STATE_OK
    Select-String "Regulatory" ${TMPF} | sort | uniq}
else{
    echo `date` >> /tmp/caught_errs.out
    cat ${TMPF} >> /tmp/caught_errs.out
    echo " "    >> /tmp/caught_errs.out
    exitstatus=$STATE_CRITICAL
    }
rm -f ${TMPF} 2> /dev/null

exit ${exitstatus}

i want to have the variables ${host}:${port} are left blank and i want to have an argument that i manually put information in and the fields populate with that information.

for example i need to connect to blank-xml.myinfo.com:30011.

the problem i am running into is when i set this up on the custom monitors i have a .bat that opens openssl but cannot open the .txt file to run commands given.

what do i need to do in order for this to work.

Update:

I have made a batch file that passes in information to openssl that is a lot smaller.

@echo off
c:\OpenSSL-Win64\bin\openssl s_client -connect help-xml.helpme.com:443

this section works great shows information on the screen that is needed. I need to send in another command to the window also but get a error stating the the < command isn't an executable or batch process.

that command is <TF80DOC><XPLN/></TF80DOC> i have tried using the & symbol and have used echo before it but still am getting the same error or the screen will pop up and close instantly with no information.

the if then statement works after i run <TF80DOC><XPLN/></TF80DOC> since this has information that is displayed the statement is looking for. But if i can't get the <TF80DOC><XPLN/></TF80DOC> to be sent to openssl after the s_client -connect help-xml.helpme.com:443 runs then the if statement will never work.

Update:

I have changed the powershell command to pipe in the command after s_client -connect help-xml.helpme.com:443

the new code looks like

@' 
<TF90DOC><XPLN/></TF90DOC>
'@ | C:\OpenSSL-Win64\bin\openssl s_client -quiet -connects_client -connect help-xml.helpme.com:443 > test1.txt 2>&1

the if then statement isn't an issue since i know how to fix that part of it. the powershell part of the code works but requires me to press enter which is not what i need it to do. i need it to execute the command automatically without user input

For the batch command i have made some slight changes to it, which are

@echo off
setlocal enabledelayedexpansion 
set "var=<TF90DOC><XPLN/></TF90DOC>"

echo echo !var! | C:\OpenSSL-Win64\bin\openssl s_client -connect tf90-xml.bsi.com:443> test1.txt 2>&1 

this command still gives me the error

< was unexpected at this time.

解决方案

Try this: (See edit below.)

@echo off
(
    echo(^^^<TF90DOC^^^>^^^<XPLN/^^^>^^^</TF90DOC^^^>
    echo;
) | C:\OpenSSL-Win64\bin\openssl s_client -connect tf90-xml.bsi.com:443 > test1.txt 2>&1

Edit:

From what you describe, it sounds like openssl is not ready for input immediately after entry of that XML, and is black holing the newline piped to stdin. So rather than dumping everything to stdin at once, you'll need to introduce a sleep of some sort, and listen to that program's stdout for the appropriate prompt.

Here's a proof of concept in JScript that I think can be applied for you as soon as I know what text openssl uses to prompt for the XML, and then for the Enter keypress. This is a similar method as described on the WSHScriptExec StdOut Property documentation page, and is more flexible than any solution attempted thusfar.

test.bat

@if (@a==@b) @end   /*  begin multiline JScript comment

:: batch portion

@echo off
setlocal

cscript /nologo /e:JScript "%~f0"

goto :EOF

:: end batch portion / begin JScript */
var osh = new ActiveXObject('wscript.shell'),
    fso = new ActiveXObject('scripting.filesystemobject'),
    log = fso.CreateTextFile('output.txt', true),
    read;

var exe = osh.Exec('cmd /c test2.bat');

while (1) {
    if (!exe.StdOut.AtEndOfStream) {
        read += exe.StdOut.Read(1); // read 1 char at a time
        if (/Arg 1:/.test(read)) {
            WSH.Sleep(50);
            exe.StdIn.Write('<TF80DOC><XPLN/></TF80DOC>\n');
            WSH.Sleep(100);

            // This is the output we wish to capture.
            read = exe.StdOut.ReadLine();
            WSH.Echo(read);
            log.WriteLine(read);

            read = '';
        } else if (/Press any key/.test(read)) {
            WSH.Sleep(100);
            exe.StdIn.Write('\n');
            break;
        }
    }
    else WSH.Sleep(100);
}
log.Close();

while (!exe.Status) WSH.Sleep(100);
WSH.Echo('Done.');

test2.bat

@echo off
setlocal enabledelayedexpansion

set /P "input=Arg 1: "

echo(Input: !input!

pause

这篇关于通过运行批处理命令进入OpenSSL的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆