piemanus

More mindless drivel

Powershell remove duplicate entries

Courtesy of http://www.secretgeek.net/ps_duplicates

PS c:\Users\JuanKerr> get-content h:\UpYerArris.txt | select-object -unique

The -Unique argument is a case sensitive

Show complete date / time in ps command

get prop

getProperty () {

   [[ -z $2 ]] && fatal “getProperty called with not enough parameters”
   key=$1

   file=$2

   [[ ! -r $file ]] && \
      fatal “getProperty($LINENO): cant find property file ($file)”

   # find the property using the key
   property=$(grep “^${key}=” $file)
   if [[ $? -ne 0 ]]
   then
      fatal “cant find key ($key) in $file”
   fi

   # remove comments from the line, if they exist
   property=”${property%%#*}”

   # return everything after the ‘=’ sign
   value=${property#*=}

   if [[ -z $value ]]
   then
      echo “null”
      return 1
   else
      echo $value
      return 0
   fi
}

Start / Stop

get_pid()
        # $1=command
        {
        /usr/ucb/ps auxwww | fgrep “$1” | fgrep -v grep | awk ‘ { print $2 } ‘
        }
start_bg()
        # $1=start_command
        # $2=match_command
        {
        pid=`get_pid “$2″`
        if [[ “$pid” = “” ]] ; then
                $1 < /dev/null > /dev/null 2> /dev/null &
                pid=`get_pid “$1″`
                wait=
                while [[ “$pid” = “” && “$wait” != “xxxxx” ]] ; do
                        sleep 1
                        wait=”x$wait”
                        pid=`get_pid “$2″`
                done
        fi
        if [[ “$pid” = “” ]] ; then
                return 1
        else
                return 0
        fi
        }

stop_bg()
        # $1=match_command
        {
        pid=`get_pid “$1″`
        if [[ “$pid” != “” ]] ; then
                kill $pid
                pid=`get_pid “$1″`
                wait=
                while [[ “$pid” != “” && “$wait” != “xxxxxxxxxx” ]] ; do
                        sleep 1
                        wait=”x$wait”
                        pid=`get_pid “$1″`
                done
        fi
        if [[ “$pid” = “” ]] ; then
                return 0
        else
                return 1
        fi
        }

Expand Props

#!/bin/ksh

expand_property() {
# $1=file.properties

awk -v PROPFILE=$1 ‘
BEGIN {
while ( (getline 0 )
if ( $0 != “” && substr($0,1,1) != “#” )
if ( (i = index($0, “=”)) != 0 )
map[substr($0,1,i-1)] = substr($0,i+1) ;
}
{
i = $0 ;
while ( match(i, /\${[0-9A-Za-z_.]+}/) != 0 )
{
k = substr(i, RSTART+2, RLENGTH-3) ;
v = map[k] ;
i = substr(i, 1, RSTART-1) v substr(i, RSTART+RLENGTH) ;
}
print i ;
}

}

get_prop() {
# $1=file.properties
# $2=property

print “\${$2}” | expand_property $1
}

http://partmaps.org/era/unix/award.html

Script to poll clearcase for changes based on a date

I’ve cheated and used perl to format the date.

#!/bin/ksh

view=myview
branch=mybranch

# Create a date 10 minutes earler than the current time
dte=$(perl -e ‘use POSIX qw/strftime/; my $date = strftime “%d-%b-%y.%H:%M:%S”, localtime(time-1200); print “$date\n”;’)
echo “Checking for change since $dte”
result=$(cleartool lshistory -recurse -since $dte -fmt ‘\”%Nd\” \”%u\” \”%En\” \”%Vn\” \”%e\” \”%o\” \n%c\n’ -branch brtype:$branch -nco /view/$view/vobs/mypath)

echo “$result”

if [[ -n $result ]] ; then
  echo Changes found
  exit 0
else
  echo No changes found
  exit 1
fi

Get disc usage for individual sub folders

for dir in `ls -da */`; do ; du -hs $dir; done;

Convince Cruise Control to show unit tests in Unit Test tab

I Love Cruise Control… Really I do…. Honest Guv

Update the Cruise control xml file to add the following to convince the unit test tab to actually acknowledge the existance of unit tests

<log>
<merge dir=”c:\MyBoringWindowsPath\MyProject\target\surefire-reports\” />
</log>

Download a Maven artefact from a repository in 1 command without the need of a POM

http://stackoverflow.com/questions/11262861/how-do-i-download-a-maven-artifact-at-the-command-line-without-using-dependency

Download a Maven artefact from a repository in 1 command without the need of a POM

For example, to get a war file. (it defaults to jar unless you specify the double colon and “war”)

mvn org.apache.maven.plugins:maven-dependency-plugin:2.8:copy -Dartifact=com.piemanus:eatpie:1.2::war -DoutputDirectory=/tmp/ -Dmdep.useBaseVersion=true –settings /home/piemanus/settings.xml

You might need to override the settings.xml to add a mirror depending on what repository you download from

Ripper