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.
To run the ant build file, open up command prompt and navigate to the folder, where the build. xml resides, and then type ant info. You could also type ant instead. Both will work,because info is the default target in the build file.
Seems like ${variable} is the same as $variable , while $() is to execute a command.
Try specifying the complete path to the script in the ant target:
<target name="test">
<exec executable="/bin/bash">
<arg value="/complete/path/to/input.sh"/>
<arg value="/tmp"/>
</exec>
</target>
This is equivalent to issuing the following command in the shell:
/bin/bash /complete/path/to/input.sh /tmp
<arg value="..."/>
denotes an argument. So you have 2 arguments to /bin/bash
, path to script & /tmp
. If your script doesn't make use of extra arguments passed to bin/bash
, then those would be ignored.
If your script input.sh
is located in /tmp
, you can either say
<exec executable="/bin/bash">
<arg value="/tmp/input.sh"/>
</exec>
or
<exec dir="/tmp" executable="/bin/bash">
<arg value="input.sh"/>
</exec>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With