Sunday, 28 February 2016

ANT Build.xml script to replace strings values.

In this post, I will be sharing two scenario's where need to replace string values in all XML files in a folder using ANT tool.




Scenario 1:

Replace various source strings to constant destination string in all XML files in a folder.

a) I placed varying source strings or list of source string into a file called Pattern.txt.
b) My destination string value is XYZ.

Pattern.txt

abccc
abc
ack
acbd

build.xml


  <loadfile property="file" srcfile="pattern.txt"/>
   <for param="line" list="${file}" delimiter="${line.separator}">
   
      <sequential>
                <replace dir="${dir}" value="XYZ">
   <include name="**/*.xml"/>
   <replacetoken>@{line}</replacetoken>
  </replace>
      </sequential>
      </for>


Scenario 2:

Replace various source strings to various destination strings in all XML files in a folder.
- I placed both varying source and destination strings in a file called Pattern2.txt.


Patter2.txt


\general\PartnerFolderLookup.m",\typetrees\gen\PartnerFolderLookup.m"
\gtmax\ShipmentStatus.m",\typetrees\gtmax\ShipmentStatus.m"
\ShippingOrder.m",\typetrees\gtmax\orders\ShippingOrder.m"

In Pattern2.txt file, both source string and destination string is varying and it is separated by a comma.

build.xml



<echo>Replacing Strings using pattern2.txt</echo>
   <loadfile property="file2" srcfile="pattern2.txt"/>
   <for param="line" list="${file2}" delimiter="${line.separator}">
     <sequential>
       <var name="index" value="1"/>
    <for list="@{line}" param="letter">
       <sequential>
           <var name="var${index}" value="@{letter}" />
 <math result="index" operand1="${index}" operation="+" operand2="1" datatype="int" />
       </sequential>
    </for>
   <replace dir="${dir}" value="${var2}" encoding="UTF-8">
       <include name="**/*.xml"/>
       <replacefilter token="${var1}"/>
   </replace>

   </sequential>
       </for>

Thursday, 11 February 2016

Linux Resources - Good Tutorials, free online courses and videos for Linux.

Linux is a basic requirement for people who are working in DevOps Domain and those working in IT Field learning Linux basics will definitely help them. Learning Linux Administration will definitely help big time in DevOps Domain.



Here, I will be sharing with you good tutorials and videos which I come across in web related to Linux / Unix. This will help you to learn Linux and can be used for future references.

1) https://www.olimex.com/wiki/Linux-Commands

This link has a list of Linux commands with its function. It is very simple, short info for each command. My fav one.


Linux Commands




2) http://www.folkstalk.com/2012/01/sed-command-in-unix-examples.html

This link has the functionality of SED command and also very good examples.

3) http://www.freeos.com/guides/lsst/

Here, you can find Linux Shell Scripting tutorials for Beginners and also a lot of shell scripting examples.

4) https://www.edx.org/course/introduction-linux-linuxfoundationx-lfs101x-2

This is Linux course, where it will give good working knowledge of Linux, navigate through major Linux distributions, system configuration and graphical interface of Linux, basic command line operations and common applications of Linux.

5) http://www.tecmint.com/35-practical-examples-of-linux-find-command/

http://www.cyberciti.biz/faq/unix-linux-list-all-files-modified-on-given-date/

In Linux / Unix Find command is very important. It is very frequently used in shell scripts. It is even very frequently asked in interview questions. Learning all options of Find command definitely helps. Above two links covers most important features of Find command.

6) http://cli.learncodethehardway.org/bash_cheat_sheet.pdf

Here is the Linux cheat sheet, which can be very handy. This cheat sheet is very good and covered most of the Linux commands.

Here are some of the Linux websites / blogs where you can explore more:


Guys, please let me know if you find any good tutorials, free online courses and videos related to Linux in the comments section, I will updating this post time to time.



Monday, 8 February 2016

Ant and Windows Batch script for safe stopping, starting and checking status of a windows service


Sometimes windows services for stopping and starting takes time. Generally, we need to make sure that, service is stopped or started before we proceed to next steps. In such scenario, below script helps to achieve such goal. With help of Ant XML script and windows batch script, I have implemented this requirement.



ManageServices.cmd

echo off

       REM Query the Service Status, stop and start accordingly
       if "%2"=="START" (
          echo "Starting the Service - %1"
          sc START %1
  :WaitForServiceToStart1
                    echo "Service is still starting. Waiting for 5 seconds"
                    ping -n 5 127.0.0.1 > NUL
                    sc QUERY %1 | find /I "STATE" | find "RUNNING"
                      IF errorlevel  1 GOTO :WaitForServiceToStart1
                         echo "%1 has started"
             )

       if "%2"=="STOP" (
            echo "Stopping the Service - %1"
            sc STOP %1
        :WaitForServiceToStop1
               echo "Service is still stopping. Waiting for 5 seconds"
               ping -n 5 127.0.0.1 > NUL
               sc QUERY %1 | find /I "STATE" | find "STOPPED"
                  IF errorlevel  1 GOTO :WaitForServiceToStop1
                     echo "%1 has stopped"
           )


This script ManageServices.cmd helps to check whether services is stopped/started.

Below ant script has two targets, stop_service and start_service. The stop_service target helps to stop the service and start_service target helps to start the service by invoking ManageServices.cmd.

 <target name="stop_service" >
 <exec executable="ManageServices.cmd" failonerror="true">
   <arg value="${env.service.name}"/>
   <arg value="STOP"/>
   </exec>
 </target>
 
 <target name="start_service" >
 <exec executable="ManageServices.cmd" failonerror="true">
   <arg value="${env.service.name}"/>
   <arg value="START"/>
   </exec>
 </target>


I had a requirement in one project where I have to check a service whether it is running or not, if the service is running only, have to proceed further. To achieve this requirement have added below script to ManageServices.cmd file.


echo off
 if "%2"=="CHECK" (
        echo "Checking the Service - %1"
    :CheckingServiceState
           ping -n 5 127.0.0.1 > NUL
           sc QUERY %1 | find /I "STATE" | find "RUNNING"
    IF errorlevel  1 echo "%1 is NOT RUNNING">service_status.txt                                             
           )

Below Ant script has target name check_service which helps to check whether a service is running or not. If the service is not running the script fails and comes out of the ant script otherwise it continues.


<target name="check_service"> 
  <exec executable="ManageServices.cmd" failonerror="true">
   <arg value="${env.service.name}"/>   <arg value="CHECK"/>
   </exec>
   
  <fail message="${env.service.name} Service is NOT RUNNING">   <condition>
 <resourcecontains resource="service_status.txt" substring="NOT RUNNING"/>
  </condition>
  </fail>
</target>

Tuesday, 2 February 2016

How to assign a godaddy domain to a blogspot / blogger ?


To assign a domain to your blog, first we need to update your domain in blogger settings as shown below. 


Once you update, the domain in the settings, the blogger will display an error below your domain.
We need to update cname's your GoDaddy account.
  • Login to your GoDaddy account and click on Manage DNS tab. 


  • In DNS ZONE FILE tab you will find use classic DNS Manager. Click on that. 
  • Update CNAME's as provided by blogger, as shown below and save ZONE File Editor. It takes some time to reflect the changes. 

Now we have done redirection for full domain i.e, www.w3devops.com. Now need to update hostname in GoDaddy, so that even naked domain i.e, w3devops.com also works for blogger. Update default IP Address i.e, 50.63.202.55 to Google IP address i.e, 216.239.36.21 under A (HOST) shown below. 



Monday, 1 February 2016

Ubuntu 15.10 - Xorg and Compiz high cpu / memory usage.

My Personal laptop suddenly became damn slow, started debugging to analyze the issue. With the help of top command identified Xorg and Compiz (more than 20 %)are using more CPU usage.

Googling helped to decrease Compiz process below 10%. Below command helped.

sudo apt-get install compizconfig-settings-manager


Still Facing issue with Xorg now and then. Temporary fix restart of laptop once or twice is resolving the Xorg high performance issue. Looking for a permanent fix. Doing Research on that, I will update this post, once I resolve this issue/bug.

Xorg CPU usage
My CPU has two cores, where one core is below 10 % usage and another CPU core is more than 90 %. I guess this is due to Xorg CPU usage in above picture, when Xorg is not using more CPU, then CPU two cores are below 10%.


Guys, if you come across any working solution please let me know through comments. I appreciate it.