Run Bash Script Using XML, ANT and Ambience 4.x Scheduler

How To Run Bash Script Using XML, ANT and Ambience 4.x Scheduler

In this post, I’ll share how to call out an external bash script using XML, ANT and Ambience 4.x Scheduler.

In this example, we are going to get Ambience Designer to create a new file onto the Linux directory /root/temp.

I am using root user and therefore I’ll create a temp sub folder under root account.

Step 1: Create an XML file In one of the folders

  1. Copy and paste the following into the xml file you created. You’ll need to create a new sub directory /temp

  2. The directory where the file is going to be execute should be /root/temp/newFile.sh

  3. XML code - execSH.xml

bashscriptANT9

<?xml version="1.0"?>

<project name"testProject" default="testInfo">
  <target name = "testInfo">
  <exec dir = "/root/temp" executable = "/bin/bash">
  <arg value = "newFile.sh"/>
  </exec>
  </target>
</project>
  1. Sample bash script - newFile.sh

  2. This will create a newFile.txt in /root/temp when executed.

bashscriptANT8

!#/bin/bash

touch newFile.txt
  1. This is the directory where Ambience will execute the bash script.

bashscriptANT7

Step 2: Ensure Path Name for Name and Build Target is valid

  1. Ensure Build Target field would be the Target Name that is specified in the XML file. Click REFRESH if it is not there.

  2. Make sure the PATHNAME in the Name field can be found in the repository on the left.

Step 3: Right Click Job and Select Run

  1. Right click on Job-RunSH.job and select run.

bashscriptANT5

  1. If the job is executed and it is successful. A newFile.txt will be created in /root/temp as shown below.

bashscriptANT4

  1. You can view the log if an exception or an error has occurred.

bashscriptANT3

  1. This can be found under the Logs menu

  1. The default directory is /tmp for Ubuntu if you use the code <exec dir = “.”

bashscriptANT1

Resources:
https://www.tutorialspoint.com/ant/ant_build_files.htm

runBashScript.zip (860 Bytes)