Jul 11

Here in my company we regularly need to check for expired certificates or just to have a proactive management checking which certificates are close to their expiry dates and issue new ones to avoid service disruption.

For that reason I’ve created a simple bash script which can be used in conjunction with nagios to check for expiring certicates.

#!/bin/sh
 
########################################################
#
#       Check certificates inside a java keystore
#
########################################################
TIMEOUT="timeout -k 10s 5s "
KEYTOOL="$TIMEOUT keytool"
THRESHOLD_IN_DAYS="30"
KEYSTORE=""
PASSWORD=""
RET=0
 
ARGS=`getopt -o "p:k:t:" -l "password:,keystore:,threshold:" -n "$0" -- "$@"`
 
function usage {
        echo "Usage: $0 --keystore <keystore> [--password <password>] [--threshold <number of days until expiry>]"
        exit
}
 
 
 
function start {
        CURRENT=`date +%s`
 
        THRESHOLD=$(($CURRENT + ($THRESHOLD_IN_DAYS*24*60*60)))
        if [ $THRESHOLD -le $CURRENT ]; then
                echo "[ERROR] Invalid date."
                exit 1
        fi
        echo "Looking for certificates inside the keystore $(basename $KEYSTORE) expiring in $THRESHOLD_IN_DAYS day(s)..."
 
        $KEYTOOL -list -v -keystore "$KEYSTORE"  $PASSWORD 2>&1 > /dev/null
        if [ $? -gt 0 ]; then echo "Error opening the keystore."; exit 1; fi
 
        $KEYTOOL -list -v -keystore "$KEYSTORE"  $PASSWORD | grep Alias | awk '{print $3}' | while read ALIAS
        do
                #Iterate through all the certificate alias
                EXPIRACY=`$KEYTOOL -list -v -keystore "$KEYSTORE"  $PASSWORD -alias $ALIAS | grep Valid`
                UNTIL=`$KEYTOOL -list -v -keystore "$KEYSTORE"  $PASSWORD -alias $ALIAS | grep Valid | perl -ne 'if(/until: (.*?)\n/) { print "$1\n"; }'`
                UNTIL_SECONDS=`date -d "$UNTIL" +%s`
                REMAINING_DAYS=$(( ($UNTIL_SECONDS -  $(date +%s)) / 60 / 60 / 24 ))
                if [ $THRESHOLD -le $UNTIL_SECONDS ]; then
                        echo "[OK]      Certificate $ALIAS expires in '$UNTIL' ($REMAINING_DAYS day(s) remaining)."
                else
                        echo "[WARNING] Certificate $ALIAS expires in '$UNTIL' ($REMAINING_DAYS day(s) remaining)."
                        RET=1
                fi
 
        done
        echo "Finished..."
        exit $RET
}
 
eval set -- "$ARGS"
 
while true
do
        case "$1" in
                -p|--password)
                        if [ -n "$2" ]; then PASSWORD=" -storepass $2"; else echo "Invalid password"; exit 1; fi
                        shift 2;;
                -k|--keystore)
                        if [ ! -f "$2" ]; then echo "Keystore not found: $1"; exit 1; else KEYSTORE=$2; fi
                        shift 2;;
                -t|--threshold)
                        if [ -n "$2" ] && [[ $2 =~ ^[0-9]+$ ]]; then THRESHOLD_IN_DAYS=$2; else echo "Invalid threshold"; exit 1; fi
                        shift 2;;
                --)
                        shift
                        break;;
        esac
done
 
if [ -n "$KEYSTORE" ]
then
        start
else
        usage
fi

All you have to do is call it like this:

./checkCertificate --keystore [YOUR_KEYSTORE_FILE] --password [YOUR_PASSWORD] --threshold [THRESHOLD_IN_DAYS]

The threshold indicates how many days are left until the expiry date is reached. I’m sure that there are several other ways of doing it but this is my own :-)

Tagged with:
Jan 09
mysql shop -BNe  "show tables like '[INSERT PATTERN HERE]'" | \
while read T; do mysql shop -e "drop table \`$T\`"; done

Nothing fancy here but this is much better than installing custom libraries to do the trick …

Tagged with:
May 30

In case you’ve tried to upgrade your XBMC application using the official repositories from “team-xbmc” you may have already noticed that the rar support was disabled. This means that you won’t be able to play movies or open subtitles without extracting it first.

You have two options to fix this issue:

a) You compile the source code and enable the non free features.

b) You use a precompiled version made by someone else.

Fortunately there are good news for those who want option b.  A guy named Nathan runs a repository where you can download XBMC with these features enabled. Just add his repository to your sources list and you are ready to go.

sudo add-apt-repository ppa:nathan-renniewaldock

apt-get install xbmc

 

You can also manually check out his repository here.

Have fun! :-)

Tagged with:
Mar 09

After several months offline I decided to implement the needed changes in order to make it work again with my current ISP.  If this is the first time you see this, I have implemented an online version of  this project.

Just check the link on the top of this website ( http://www.davidgouveia.net/android-ksoap2-stub-generator/ ). All you need to do is input the url of the wsdl that you want to generate the stub.

Have fun :-)

Tagged with:
Sep 15

Hi,

Today I’m going to show you a very small script that allows you to convert any video (as long as it is supported by mplayer) to a GIF.

Required tools:

* mplayer

* convert

 

mplayer is popular media player available for multiple operating systems that support a wide range of video formats. The convert tool is an utility that lets you convert between multiple image formats among other definitions.  Since the mplayer takes screenshots using jpeg format, we need to use the convert tool to do the convertion to aGIF format.

 

Copy the following code, save it to a file and change its permissions (chmod a+x) and you are ready to roll :)

 

 

#!/bin/sh
TMPDIR=/tmp/animated
shopt -s nocaseglob
if [ ! -d "$TMPDIR" ]
then
        mkdir $TMPDIR
fi
 
\rm $TMPDIR/* &> /dev/null
 
if [ $# -lt 3 ]
then
        echo -e "Usage: $0    []\nExample:\n$0 00:15:11 10 myvideo.avi 320:240"
        exit 1
fi
 
if [ -n "$4" ]
then
        SCALE="scale=$4"
fi
 
echo "Generating screenshots. Please be patitent..."
mplayer -ao null -ss $1 -endpos $2 $3 -vo jpeg:outdir=$TMPDIR/ -vf $SCALE &amp;&gt; /dev/null
if [ -f $TMPDIR/00000001.jpg ]
then
        echo "Finished generating frames. Assembling the animated GIF..."
        convert -delay 5 $TMPDIR/*.jpg $TMPDIR/output.gif
        echo "Done! Please check the $TMPDIR/output.gif"
        exit 0
else
        echo -e "Oops\! Something went wrong and the frames were not generated. Check your parameters\!"
        exit 1
fi

Just try it and let me know ;-)

Tagged with:
Aug 22

As a sysadmin, I should always search and check for errors on every machine that I manage. Unfortunately one of them has an Adaptec 5405 which I forgot to monitor using nagios and just like Murphy’s Law says – “Anything that can go wrong will go wrong” – something went wrong and I have lost information. Not a really big problem because I have backups of everything but it could have been avoided if I had monitored the status of the Adaptec just the way I do with software raid arrays (/proc/mdstat rules!).

So I developed another simple script using Perl (again :-P ) to check the status of all the available arrays.

#!/usr/bin/perl -w
use strict;
use warnings;
 
my $adaptec_tool = "/usr/src/cmdline/arcconf";
 
my $dump = `$adaptec_tool getconfig 1 ld`;
my @raids = ();
 
while ($dump =~ /Logical device name.*?:.*?([a-z0-9]+).*?raid level.*?:.*?([0-9]+).*?status of logical device.*?:.*?([a-z0-9]+)/gsi) {
        push @raids, {"name" => $1, "raidlevel" => $2, "status" => $3};
 
}
 
foreach my $raid (@raids)
{
        if ( $$raid{status} ne "Optimal" )
        {
                print "Critical: Raid not Optimal! (Array Name: $$raid{name}, Level: $$raid{raidlevel}, Status: $$raid{status})\n";
                exit(1);
        }
}
 
print "OK: All arrays in optimal shape\n";
exit (0);

You just need to download the “Adaptec Storage Manager” to connect to the RAID card and read the status. You can use this link to do it.

Tagged with:
Apr 23

This is probably a common problem among all the people trying to get audio over HDMI under Linux using an EN210 graphics card (or similar).

Even though the HDMI may appear in your available cards listed in proc (/proc/asound/cards) you will probably see that you cannot find it using the aplay utility. Just check it running the command “aplay -l”. The HDMI device isn’t listed here isn’t it?

The reason for this issue is related to the ALSA driver version 1.0.21 (or older) which is quite buggy for these graphics cards.

You can check which version you are using by executing the following command:

cat /proc/asound/version

If you get a version older than 1.0.21 then you need to upgrade it. You can check your favourite distribution’s repository for an update or you can try to compile it from source code.

If you can’t find an update, check this page: http://ubuntuforums.org/showthread.php?t=1681577

It might help you ;-)

Tagged with:
Apr 23

If you are running the latest version of Ubuntu and tried to mount a NTFS filesystem you probably already know that you can’t and maybe you have even seen an error like “mount exited with exit code 21″.

This seems to be due to a bug in libfuse2 and/or fuse-utils package. To fix this temporarily you can downgrade both packages to a prior version. libfuse2 and fuse-utils version 2.8.1-1.1ubuntu2.2 seem to be OK but 2.8.1-1.1ubuntu3.2 is useless.

Just download both packages and install them:

http://launchpadlibrarian.net/60433788/libfuse2_2.8.1-1.1ubuntu2.2_i386.deb

http://launchpadlibrarian.net/60433786/fuse-utils_2.8.1-1.1ubuntu2.2_i386.deb

Don’t forget that these are 32bit packages. If you are using 64bit OS then download the needed packages.

sudo dpkg -i libfuse2_2.8.1-1.1ubuntu2.2_i386.deb
sudo dpkg -i fuse-utils_2.8.1-1.1ubuntu2.2_i386.deb

Problem solved :-)

Tagged with:
Sep 02

After upgrading my HTPC to Ubuntu 10.04, nvidia drivers stopped working without any reason. After googling a bit, all the answers pointed to a problem related with Ubuntu upgrade system not updating restricted drivers. I have tried manually to update and use all the available versions, but without any success…until I found the cause and solution.

It happens that Ubuntu does not remove old drivers correctly, leaving you with multiple versions which were confusing the operating system. The solution was to purge the system from all nvidia drivers and reinstall just one of them.

You can run the following commands to clean the system:

sudo dpkg --get-selections | grep nvidia | grep -v deinstall | awk '{print $1}' | xargs sudo apt-get remove -y
sudo apt-get install nvidia-current
sudo nvidia-xconfig

sudo reboot

The system will then reboot and if everything is OK, Ubuntu will be as good as new.

Tagged with:
Jun 28

O port do sistema operativo Android está cada vez mais perto do HTC HD2. Depois de ultrapassados os problemas relacionados com o kernel (que aparentemente estavam relacionados com algumas instruções extra do processador) foi uma questão de dias – mais concretamente dois – até que conseguissem inicializar o Android. Nesta fase ainda há muitos drivers que não se encontram a funcionar e que fazem com que ainda seja inútil para qualquer utilizador, mas foi mais um passo na direcção certa.

Podem inclusive ver um video do processo de inicialização do sistema:

O próximo passo parece estar relacionado com os drivers do touchscreen, o famigerado ELAN B81 que mesmo após alguma insistência sobre o fabricante, este não libertou a informação necessária para ser criado o driver para linux.

Mais informações na thread oficial do port deste sistema operativo:

http://forum.xda-developers.com/showthread.php?t=651632

Tagged with:
preload preload preload