Visualizzazione post con etichetta Script. Mostra tutti i post
Visualizzazione post con etichetta Script. Mostra tutti i post

[Script] automatically crontab update


Sometimes you need to update a crontab configuration in multiple enviroments (staging, production...).


If you have properly configured ssh, you can use this shell function:


function addToCrontabIfNotAlreadyPresent() {
HOST=$1

ssh -o "BatchMode yes" $USER@$HOST << EOF

crontab_line="5 0 * * * cd ~/yourproject/ && ./script/run.sh >/dev/null 2>&1-"
alreadyInCrontab="\$(crontab -l | grep "\$crontab_line" )"

if test "\$alreadyInCrontab" == ""; then
crontab -l > /tmp/updating_crontab.tmp
echo "\$crontab_line" >> /tmp/updating_crontab.tmp
crontab /tmp/updating_crontab.tmp
rm /tmp/updating_crontab.tmp

echo "Crontab updated";
else
echo "Crontab ok";
fi
EOF
}

USER='your_user'
addToCrontabIfNotAlreadyPresent "10.10.10.10"

[Test] How to sort junit tests by execution time


Today with my colleague Luca Pucacco i've searched a method to detect which (junit) test are slow without any known or reasonable motivation. When you run a junit suite with eclipse you can see the execution time but you are not able to see an order.
So:
  1. export Test run with the gui; let's call this file SuiteOutput.xml
  2. Open a shell and write:
  3. cat SuiteOutput.xml | grep "<testsuite" | sed 's/\(.*time="\)\([^"]*\)\(.*\)/\2\1\2\3/' | sort -rg

With cat SuiteOutput.xml | grep "<testsuite" you are simply extracting the interesting rows
With sed s/..../../ we are going to substitute something. In details. Let's assume a row is in the form of:
<testsuite name="xxxTest" time="10.0">
The first group
(.*time="\) is the first part of the row ( <testsuite name="xxxTest" time=" )
The second group
([^"]*\) is all before the " character ( the 10.0 string)
The last group is the rest ( ">)

The final row contains as the first information the execution time. The last operation is sorting these data by evaluating it like a number and not like a string.


[Script] subversion diff ignoring white space


Try it when you need to look differences in your code without noise due to formatting rules:
svn diff -x "-u -w" (-r revisionNumber)

and eventually :


patch -p0 -l < (file name)


----
Thanks to Marco Gulino

[Script] verifica che nel tuo war non finiscano diverse versioni della stessa libreria!


#!/bin/bash

warfile=$1

function strip_version_numbers() {
# converte foo/bar-1.2.3.jar in foo/bar.jar
ruby -pe 'gsub($1, "") if $_ =~ /^.*(-[0-9.]+)(-bin)?.jar/'
}

# check there are no duplicates entries in war
if jar tf $warfile | strip_version_numbers | sort | uniq -c | sort -nr | head | grep '^ [2-9]'
then
echo "duplicate entries found"
exit 1
fi