Monday, May 11, 2015

Linux - remote ssh and execute commands


The below script will make copy of the file. insert the desired line as the second line.

for LINE in $(cat machines.csv)
do
        ssh root@$LINE "cp /etc/xyz.conf /etc/xyz.conf.old; sed -i '2i nameserver 10.xx.xxx.xxx' /etc/xyz.conf"
done

Grep and Awk Tips and Examples

Remove duplicates and retain the order
awk ' !x[$0]++' 1.txt > 2.txt


Grep regex to find strings only contains alphabets 

grep "^[a-zA-Z]*$"

alphabets, numbers and + (this is typical for a query string)
 grep "^[a-zA-Z0-9+]*$"



Grep few characters after match - this case 15 characters after match - for getting the various calls to www.xyz.com

grep -E -o "www.xyz.com \"GET \/.{0,15}" httpd2-xyz.com.access-log.1370347200

-o - to show only the match
-E - extended regular expression


Grep - escape double quote
\"

-as in above example, before GET



Various calls goes to www.xyz.com from apache logs
grep -E -o "www.xyz.com \"GET \/.{0,15}" httpd2-xyz.com.access-log.1370347200 | awk '{ print $3}' | awk '{ if(match($0,"?")) { split($0,a,"?"); print a[1]}}' 



Grep for lines ending with q= - from the logs which has no query param
grep '.*q=$'


Sed Tips

Remove empty lines

sed '/^$/d'


Replace a string

sed 's/original/new/' - only first occurence of the line
sed 's/original/new/g' - all occurences

JMeter JSON Path extractor example

1.      Json path extractor – this comes from JMeterPlugins-ExtrasLibs.

Issue to use array of response by referencing _1 and _2 all resolved by moving from v1.1.3 to v1.2.1
Online json path extractor - http://jsonpath.curiousconcept.com/


JMeter Response Assertion - matching for pattern

1.      Response assertion matching values in response text to validate the success of the request

a.      To validate a value from input, for example SSN value, <SSN>${ssn}</SSN>
b.      For any value in the response, but with a pattern
                                                    i.     <SSN>.*</SSN>
c.      <!- - no errors on the page -->


JMeter Adding a random number to input, within range of

${__Random(100000,999999)}

JMeter Socket read timeouts from jmeter

Add “HTTP Request Defaults” and assign timeouts for connect and Response