For using sed inside a shell script, The variable should be in "double quotes" and the command in 'single quotes'. Following is the example
#!/bin/bash
usage () {
echo "$0 -s < name> -r <replace name> -f <file name>"
exit
}
while getopts s:r:f: option
do
case "$option" in
s) search="$OPTARG";;
r) replace="$OPTARG";;
f) filename="$OPTARG";;
\?) usage
esac
done
sed -i 's/'"$search"'/'"$replace"'/g' "$filename"
Saturday, October 24, 2009
Using variable with sed inside a shell script
Posted by Vishnu Agrawal at 10:39 PM 0 comments
Labels: sed, shell scripting
Saturday, October 3, 2009
https redirection handling in httpunit
In httpunit when you are requesting a http page and if the page internally redirects to a https page, httpunit throws following error and response is not received:
sun.security.validator.ValidatorException: PKIX path validation failed: java.security.cert.CertPathValidatorException: timestamp check failed
To resolve this error, add following code in your httpunit program.
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import java.security.cert.*;
try{
SSLContext context = SSLContext.getInstance("SSLv3");
TrustManager[] trustManagerArray = { new NullX509TrustManager() };
context.init(null, trustManagerArray, null);
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostnameVerifier());
}catch(Exception e) {
e.printStackTrace();
}
class NullX509TrustManager implements X509TrustManager {
/* Implements all methods, keeping them empty or returning null */
public X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] chain, String authType) {
}
public void checkServerTrusted(X509Certificate[] chain, String authType) {
}
}
class NullHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
Posted by Vishnu Agrawal at 4:23 PM 0 comments
Getting thread dump for java application
When an java application server freezes or becomes non-responsive, it is recommended to generate a thread dump for the application. A thread dump is a user-friendly snapshot of the threads and monitors in a Java Virtual Machine (JVM). A thread dump can range from fifty lines to thousands of lines of diagnostics depending on how complex your application is.
On UNIX platforms you can send a signal to a program by using the kill command. This is the quit signal, which is handled by the JVM. On Solaris you can use the command kill -QUIT process_id, where process_id is the process id of your Java program.
run the command kill -QUIT
On Windows platform, enter the key sequence <CTRL> <break>
Thread States :: The key used for the thread states in Thread dump is:
R ==> Running or runnable thread
S ==> Suspended thread
CW ==>Thread waiting on a condition variable
MW ==> Thread waiting on a monitor lock
MS ==> Thread suspended waiting on a monitor lock
Posted by Vishnu Agrawal at 3:57 PM 0 comments
Labels: java
Monday, July 20, 2009
Run sql query from command line
We all know to run sql scripts (.sql files) from command prompt but sometimes we need to run a sql query from command prompt. It is sometimes necessary when we have to fetch a query result from a script (shell/perl) and process it. By following way, we can run a sql query from command prompt.
echo "select * from dual;" | sqlplus -S user/pwd\@sid
Posted by Vishnu Agrawal at 8:16 PM 0 comments
Labels: perl script, sql
Send Email from perl script
Sometimes we do not have enough privileges to install perl modules on the host system and we have to work with ideal installation of perl. In that case, simpler way to send emails using perl is to use sendmail command. Following function can be used to send emails in perl.
sub sendEmail
{
($from, $to, $subject, $message) = @_;
my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: $to\n";
print MAIL "Subject: $subject\n\n";
print MAIL "$message\n";
close(MAIL);
}
above function can be used as below:
sendEmail("vishnu\@test.com", "vishnu\@mytest.com", "Test sendEmail.", "Testing sendEemail function.");
Posted by Vishnu Agrawal at 8:02 PM 0 comments
Labels: perl script
Thursday, June 25, 2009
Recover Photos from SD card
Recently my family went for a annual trip and accidentally removed the photos from my digital camera. They asked me if somehow we could recover those photos. As obvious, i did some googling and found out that there are many software available which can recover data from your SD card (most of them are paid and i was looking for any free alternative :) ). Finally i got this one PhotoRec (http://www.cgsecurity.org/wiki/PhotoRec). It do not require any installation, just download the software and start using it. (obviously you should have SD card reader in your system). Thanks to it, I could recover all photos.
While googling, i found other free software as well but didn't give them try, one of them was Mjm (http://www.mjm.co.uk/freephotorecoverysoftware.html)
Posted by Vishnu Agrawal at 10:32 PM 1 comments
Labels: digital camera
Sunday, May 31, 2009
Building brand value at workplace
Recently read an article from Delhi Times Ascent. Very inspiring and true
There are often times when an employee may wonder, how do i stand out in a team? And experts say that by simply completing tasks assigned on time or working hard for longer hours, may not necessarily be the answer. They say it takes more than just one's work and job profile to be outstanding. This is where the role of crafting your own "USP"(Unique Selling Proposition) comes into the picture.
Crafting your USP:
According to experts, the first thing to do while brand-building is to identify the qualities and characteristics that give you an edge over the rest. Understand your strengths/abilities and use it towards your advantage at the workplace. Maintaining good relations with people whom you deal with will also add to your brand value. Self-branding is no easy task. It comprises of identifying your best personality traits and displaying it from time to time through enhanced performance and higher productivity. This will not only get you noticed but will also give you an edge over your colleagues.
Build your brand:
- Be a great team-mate and a supportive colleague.
- Be passionate about your job and make others know that you are excellent in your particular task/job.
- Finish the tasks assigned to you on time with exceptional quality.
- Be proactive and discuss your views on improving things with your senior officials.
- Bring in innovations into your project/tasks to make it more efficient.
Posted by Vishnu Agrawal at 9:07 PM 0 comments
Labels: HR
Sunday, May 17, 2009
Comparing Excel Files
While testing any reporting application, one comes under situations when he/she have to compare two excel files. If the excel sheets are small, its easier to compare them manually but as long the sheets becomes large, you need some automated way to compare those.
Earlier, i used to export those files as csv and then comparing them using perl scripts but it was an overhead to exporting and then comparing so i thought of doing something within the excel sheets itself. After googling, i found that it can be done by using Excel Macros. I did try that, but found that you need to open those excel files in Microsoft Excel and then apply the macro, which again i didn't like as it require to open MS Excel. I was interested to have a program which i can run from command prompt. Finally i got my solution. I converted the above macro as a standalone vb script program and used it from command prompt.
The great benefit with this script is that i can take control of displaying the diff results (currently, i am highlighting the rows in the excel sheet itself.)
to run this program, open command prompt and run following command:
C:\> cscript /nologo ExcelCompare.vbs <ExcelFile1> <ExcelFile2>
Following is the program:
Posted by Vishnu Agrawal at 11:44 PM 0 comments
Run a Visual Basic Script Program from a command prompt
A Visual Basic script program can be run from a DOS prompt. cscript command can be used for this purpose.
C:\>cscript <pathToVBScriptFile>
by default cscript command displays the Microsoft Header but this can be avoided by providing /nologo argument.
Microsoft (R) Windows Script Host Version 5.6
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
C:\>cscript /nologo <pathToVBScriptFile>
User can also take control to take input and display the output on the console. For that user had to use following options in the VB Script.
dim input
dim output
dim name
set output = wscript.stdout
set input = wscript.stdin
output.write "Enter Your Name : "
name = input.readline
Posted by Vishnu Agrawal at 12:04 PM 0 comments
Labels: vbscript
Monday, April 27, 2009
Compare two files line by line
Posted by Vishnu Agrawal at 11:09 PM 0 comments
Labels: perl script
Sunday, April 19, 2009
Flex automation testing with QTP
QTP can be used to test the Flex application. You need to perform following steps to setup recording a flex application with qtp.
- Install QTP 9.2
- Install Internet Explorer
- Install flash player debug version for IE
- Install Flex Builder 3
- Install QTP plugin of flex from FLEX_BUILDER3/Installers/QTP_Plugin_Installer
- Compile your flex application with automation libraries. It can be done in two ways; either use -include-libraries parameter in Flex Builder3 or use mxmlc ant task. This step is must otherwise QTP will not recognize the flex application
- To record a test in QTP, you must compile the application’s SWF file and generate the HTML wrapper files. The main wrapper file defines the application as an object on the page and embeds it so that Flash Player is invoked when the page is requested. You cannot request the application’s SWF file directly. You can write the HTML wrapper yourself, or generate it with the compiler.
- Start QTP
- QTP wil show the all plugins on startup, select the flex plugin and continue
- Start recording for your flex application.
Posted by Vishnu Agrawal at 7:23 PM 18 comments
Build FLEX application with automation libraries using Flex3 SDK and ANT
To test Flex Application with any automated testing tool (like QTP), automation libraries should be included in the application SWF file to make the application testable. Flex Automation libraries are not part of the Flex SDK, these comes with Flex Builder 3. If you are using Flex SDK and ANT as build tool, you need to perform following steps to compile your application.
- Copy flex automation libraries (automation.swc, automation_agent.swc, automation_dmv.swc, automation_flashflexkit.swc) from Flex Build 3 installation (/frameworks/libs) to your local directory (let say C:\flex-automation).
- Copy automation tool library (qtp.swc in case if you are using QTP as testing tool) in C:\flex-automation
- Copy flex agents (automation_agent_rb.swc, automation_rb.swc) in C:/flex-automation/locale/en_US. Flex agent facilitates communication between a flex application and an automation tool.
- Copy FLEX_HOME/frameworks/flex-config.xml to flex-config-auto.xml and keep it in same directory (FLEX_HOME/frameworks)
- Add following entries in include-libraries section of flex-config-auto.xml
- <include-libraries>
<library>C:/flex-automation/automation.swc</library>
<library>C:/flex-automation/automation_agent.swc</library>
<library>C:/flex-automation/automation_dmv.swc</library>
<library>C:/flex-automation/automation_flashflexkit.swc</library>
<library>C:/flex-automation/qtp.swc</library>
</include-libraries> - In mxmlc task of ant build file specify load-config path as
- <load-config filename="FLEX_HOME/frameworks/flex-config-auto.xml"/>
- Add compiler-library-path in mxmlc task
- <compiler.library-path dir="C:/flex-automation" append="true">
<include name="locale/en_US" />
</compiler.library-path>
<mxmlc file="${APP_ROOT}/Main.mxml" output="${build.dir}/main.swf">
<load-config filename="${FLEX_HOME}/frameworks/flex-config-auto.xml"/>
<source-path path-element="${FLEX_HOME}/frameworks"/>
<compiler.library-path dir="${FLEX_HOME}/frameworks" append="true">
<include name="libs" />
<include name="locale/en_US" />
</compiler.library-path>
<compiler.library-path dir="${FLEX_AUTOMATION_HOME}" append="true">
<include name="locale/en_US" />
</compiler.library-path>
</mxmlc>
mxmlc ANT task comes with flexbuilder3 and flex sdk. In flex builder, the location of task is : _FLEX_BUILDER_INSTALL_LOCATION_\sdks\3.0.0\ant\flexTasks.jar
To use this ant task in ant build file use ant taskdef task as below:
< taskdef resource="flexTasks.tasks" classpath="_PATH_TO_TASK_/
Posted by Vishnu Agrawal at 6:02 PM 11 comments
Labels: flex
Wednesday, April 15, 2009
JMeter: run tests using ANT
Do you run your test cases in jmeter GUI, i really never like to run my tests in it. I always like to have command line options or preferably ANT. Following are the steps to run any JMeter test cases using ANT:
1. Install ANT and JMeter
2. Copy ant-jmeter.jar ant ANT_HOME/lib directory.
3. Create a common.xml file (as mentioned below) which can be referred by any Jmeter Test plan.
4. Create a build.xml for every test plan, which refers to common.xml
5. Use xslt task to create the html report of the test cases.
common.xml
<project name="jmeter-test-common" default="run" basedir=".">
<property name="jmeter.dir" value="C:/Jmeter"/>
<taskdef name="jmeter" classname="org.programmerplanet.ant.taskdefs.jmeter.JMeterTask"/>
<target name="run-test">
<echo message="${jmeter.dir}"/>
<jmeter jmeterhome="${jmeter.dir}"
testplan="${test.dir}/${jmeter.file}.jmx"
resultlog="${test.dir}/${jmeter.file}.jtl">
<property name="jmeter.save.saveservice.output_format" value="xml"/>
<property name="jmeter.save.saveservice.assertion_results" value="all"/>
<property name="request.threads" value="${request.threads}"/>
<property name="request.loop" value="${request.loop}"/>
<jvmarg value="-Duser.dir=${test.dir}"/>
</jmeter>
<echo message="Generating Report ..."/>
<xslt in="${test.dir}/${jmeter.file}.jtl"
out="${test.dir}/${jmeter.file}_summary.html"
style="${jmeter.dir}/extras/jmeter-results-report_21.xsl"/>
<xslt in="${test.dir}/${jmeter.file}.jtl"
out="${test.dir}/${jmeter.file}_detailed.html"
style="${jmeter.dir}/extras/jmeter-results-detail-report_21.xsl"/>
</target>
</project>
<project name="my-test" default="run" basedir=".">
<import file="${ant.file.my-test}/common.xml"/>
<target name="run">
<antcall target="run-test">
<param name="jmeter.file" value="LOGIN"/>
<!-- here LOGIN is the jmx file name -->
<param name="test.dir" value="${ant.file}/.."/>
<param name="request.threads" value="5"/>
<param name="request.loop" value="1"/>
</antcall>
</target>
</project>
Posted by Vishnu Agrawal at 11:53 PM 25 comments
JMeter: Using Variables
In JMeter value of user.dir varaible is set to jmeter/bin directory. Jmeter saves and loads the test script from user.dir, so by default it is jmeter/bin. But what if your test scripts are saved in directory other than jmeter/bin which is the case most of the time.
We can override the value of this varaible in jmeter/bin/jmeter.properties as mentioned below:
user.dir=C:/perftest/mytest
Now the jmeter wil look for test script in C:/perftest/mytest instead of its default location. We can also specify this varaibale as jvm arg; if we are running jmeter from command prompt. (-Duser.dir=C:/perftest/mytest)
Accessing user.dir value in Jmeter test plan
In Test Plan -> User Defined Variables add a new variable
Name: userdir
Value: ${__property(user.dir)}
Now this userdir varaible can be used in jmeter test plan as location of the test script (${userdir}).
Reading values from a file
${__CSVRead(${userdir}/env.txt,0)} -> It will read the first column of the first line from the env.txt file
__P
This is a property function which is intended for use with properties defined on the command line. Unlike the __property function, there is no option to save the value in a variable, and if no default value is supplied, it is assumed to be 1.
${__P(request.threads)} -> return the value of request.threads
${__P(request.loop)} -> return the value of request.loops
${__javaScript(${__P(request.threads)}*2)} -> multiply the value of request.threads by 2
Posted by Vishnu Agrawal at 11:24 PM 1 comments
Labels: jmeter
Use JMeter to load test FLEX Applications
Flex applications use a binary protocol called AMF (Action Message Format) that they use to remotely communicate with the server. The easiest way to use JMeter with a Flex application is to use HTTP proxy server.
- Create a New Test Plan
- Right Click on Test Plan, Add -> Thread Group
- Right Click on Thread Group, Add -> Config Element -> HTTP Request Defaults
- Select 'HTTP Request Defaults'
- Specify Server Name or IP, for eg. www.mysite.com
- Specify Port number, eg. 8888
- Specify protocol, i.e. http
- Specify Path, foe eg. /main/index.html
- Select Work Bench
- Right Click on Work bench, Add -> Non-Test Elements -> HTTP Proxy Server
- Select 'HTTP Proxy Server'
- Specify port number for proxy (default is 8080)
- Set Target Controller to 'Test Plan -> Thread Group'
- Set inlude URL patterns , .* to include all
- Set exclude URL patterns, for eg. , .*\.gif, .*\.png, .*\.css, .*\.js
- Open Internet Explorer
- Goto Tools -> Internet Options -> Connections -> LAN settings
- In Proxy Server panel, specify address as 'localhost' and port number (which is specified in
meter's HTTP proxy server, i.e. 8080)
- Select 'HTTP Proxy Server'
- Click on Start
- Open IE and open URL 'http://www.mysite.com:8888/main/index.html'
- As soon as you visit the URL jmeter starts the recording, and you can see all the requests in
METER
- For AMF requests (for Adobe FLEX), request is saved as file with extension '.binary' in the bin
irectory of jmeter
- Click on Stop button of 'HTTP Proxy Server' to stop the recording.
Test Plan is ready. You can modify it now according to your requirements.
Proxy Server setup document from Apache:
http://jakarta.apache.org/jmeter/usermanual/jmeter_proxy_step_by_step.pdf
Posted by Vishnu Agrawal at 11:00 PM 9 comments
Sunday, March 22, 2009
PERL round function
Following is the round function in PERL, which you can put into your script and actually call to round numbers instead of cutting them with ceil or cut.
In the following round function, you can specify the number to round and the number of digits to show after the decimal.
sub round {
my $number = shift || 0;
my $dec = 10 ** (shift || 0);
return int( $dec * $number + .5 * ($number <=> 0)) / $dec;
}
$result = round(123.4567,3);
it would return 123.457
Posted by Vishnu Agrawal at 9:30 PM 2 comments
Labels: perl script
About url in firefox
There are few special URLs which begins with about: that you can type into the firefox location bar:
about: => The same page as Help -> About
about:blank => A blank page
about:cache => Displays cache statistics and directory location
about:config => GUI for modifying user preferences
about:plugins => List all plugins
about:logo => Displays the firefox logo
There is an extension available for firefox to save advanced preferences. gui:config makes it easier to change preferences that can only be found in the “about:config”. This add on can be downloaded from https://addons.mozilla.org/en-US/firefox/addon/5523
Posted by Vishnu Agrawal at 9:12 PM 0 comments
Labels: firefox
Friday, March 20, 2009
TOAD: Tips and Tricks
Tips for TOAD's sql editor
- Tired of typing long column/table name while writing a sql query? Use Auto Complete feature of TOAD. Type a part of the table/column name and then press CTRL + . (period). TOAD will automatically identify the name of the table/column and fill in the rest of the word. If there is more than one option available then TOAD will list all the available options and you can select from there.
- Forgot the queries which you ran in past? In TOAD's sql editor Press ALT + UP/DOWN key and it will show you the past queries (similar to SQL recall feature , F8)
- You constantly making spell mistakes while writing queries? Right click in the editor and select “Editing Options”. On this new option screen click on the “Auto Replace” button in the bottom right hand corner. Here you will see a list of the common misspelled words our user’s experience. If there are words you constantly misspell, then you can add them to the list by using the “Add” button. So, now in the editor if you mistype the word “select” as “seelct” … it will automatically fix itself once you hit the spacebar.
- Wanted to control number of rows in your grid? Use OCI array size option to tell toad how many rows you want retrieved at a time. If you want to only see first 100 rows of an table, set this option to 100.
- Generating Schema Documentation- From the Database menu, select Report -> HTML Schema Doc Generator.
Posted by Vishnu Agrawal at 9:53 PM 0 comments
Labels: toad