且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过蚂蚁执行Shell脚本

更新时间:2023-12-05 12:24:34

我知道你得到了解答您的问题,并已经转移。不过,我想指出为后人几件事情。你为什么要使用蚂蚁?似乎你会只是一个shell脚本更好。

不要Exec的出来的bash脚本。你没有列出所有脚本的内容,但 call.sh input.sh 是微不足道的原生地做蚂蚁。这将使自主构建脚本平台以及整合的日志记录。
您可以直接从蚂蚁处理您的输入与输入任务

 <输入
    消息=请输入单位名称:
    方法addProperty =org.name
/>

不过我强烈建议你不要有等待用户输入构建脚本。您可以在 org.name 属性,然后简单地指定它的命令行,当你建立:蚂蚁-Dorg.name =牦牛

您不需要做替换找到的SQL文件,你可以在SQL中使用变量,并通过他们在执行进去。 (实施将取决于DB)

这也伤害了我的灵魂,你的例子是从一个root shell。不要以root身份登录。

I have a shell script named Call.sh which internally calls other scripts (i.e. .sh) and is working fine for me. Now i want to execute Call.sh from ant utility. I have made an build.xml which invokes the .sh. But one of the scripts asks for input, but ant doesn't give the chance to me to give the input due to which further operations fails. Please find below codes

Build.xml

<project name="Sample" default="info">
<target name="info">
<exec executable="/bin/bash">
<arg value="/full path/Call.sh"/>
<arg value="/tmp"/>
</exec>
</target>
</project>

Call.sh

    #!/bin/bash
    echo "Begining the execution......"
    sleep 1
    sh ./input.sh
    sh ./AutomateCom.sh
    sh ./Clean.sh
    echo "*****_______*****_______"

input.sh

    #!/bin/bash

    echo "enter the Organization name"
    read Orgname
    echo "Orgname is : $Orgname"
    sed "s/000/$Orgname/g" Final.sql >> ExecuteID.sql
    echo "Organization name has been replaced with $Orgname"

when i run the ant: It runs continously....below is the o/p when i say ant

[root@krog2-rhel5-64 Work]# ant
Buildfile: /root/test/Work/build.xml

info:
     [exec] enter the Organization name
     [exec] Orgname is :
     [exec] Organization name has been replaced with

BUILD SUCCESSFUL
Total time: 0 seconds
......................................

What i expect when i run ./input.sh,in same way ant should ask me for input

[root@krog2-rhel5-64 Work]# ./input.sh
enter the Organization name
**yak**
Orgname is : yak
Organization name has been replaced with yak
  However ant doesn't give me opportunity to prompt for the user input. Any suggestions.

I understand you got your question answered and have moved on. However I want to point out a few things for posterity. Why are you using ant? it seems you'd be better off with just a shell script.

Don't exec out to bash scripts. You didn't list the contents of all your scripts but call.sh and input.sh are trivial to do natively in ant. This will make your build script platform independent as well as consolidate the logging. You can handle your input directly from ant with the input task

<input
    message="Please enter organization name:"
    addproperty="org.name"
/>

However I'd strongly urge you to not have a build script that waits for user input. You can make the org.name a property and then simply specify it on the commandline when you build: ant -Dorg.name=yak

You needn't do a find replace on the sql file, you can use variables in the sql and pass them in when you execute it. (implementation will be db dependent)

It also hurts my soul that your examples are from a root shell. don't login as root.