Wait for a file in bash

By Joao

wait_till_exists "/tmp/myfile", 5

function wait_till_exists {


until ls -l $1 &> /dev/null
if [ $counter -gt $timeout ]; then
echo "Timeout waiting for $1 to exist"
exit 1
echo "Waiting for $1 to exist: $counter of $timeout"
sleep 1

categoriaTechnology commentoNo Comments dataMay 19th, 2015
Read All

Convert sound file to video

By Joao

ffmpeg -loop 1 -i background.jpg -i input.mp3 -vcodec mpeg4 -acodec copy -shortest -qscale 5 video.mp4

categoriaTechnology commentoNo Comments dataNovember 1st, 2014
Read All

Capture stdout/stderr and exit code in perl

By Joao

use strict;
use warnings;

use IPC::Open3;

my $command = "ls -l /tmp /nonexistant_path";

local (*my_in, *my_out, *my_err);
my $pid = open3(\*my_in, \*my_out, \*my_err, $command) or die($!);
my $out = do { local $/; };

my $err = do { local $/; };

waitpid($pid, 0);
my $exitcode = $? >> 8;

print "Return code = $exitcode
stdout = $out

stderr = $err

categoriaTechnology commentoNo Comments dataOctober 29th, 2014
Read All

Speed up ssh logins

By Joao

Share the same ssh connection for different sessions. This means only the first one actually needs to login:

Host *
ControlMaster auto
ControlPath /tmp/ssh_mux_%h_%p_%r

Disable GSSAPIAuth, sometimes ssh takes a long time figuring out if it needs to use it or not

Host *
GSSAPIAuthentication no

categoriaTechnology commentoNo Comments dataJuly 27th, 2013
Read All

Force cfengine client to download/execute new promises

By Joao

On the hub:

on the hub:
cf-agent -K -f failsafe.cf

On the client

rm -f /var/cfengine/inputs/cf_promises_validated
cf-agent -K -f failsafe.cf # Download new promises
cf-agent -vK #execute new promises in verbose mode

categoriaTechnology commentoNo Comments dataJuly 5th, 2013
Read All

Ignore SSL certificates in LWP

By Joao

Recents version of Perl’s LWP validate the server’s SSL certificate on HTTPS requests. To revert to the old behaviour (ignore server certificate):

use LWP::UserAgent;
use IO::Socket::SSL qw();

my $ua = LWP::UserAgent->new();
$ua->ssl_opts( SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE, SSL_hostname => '', verify_hostname => 0 );

The SSL_hostname option is only required if you intend to fake the “Host” header ( so that it doesn’t mismatch with a similar header in the SSL layer ).

categoriaTechnology commentoNo Comments dataJuly 4th, 2013
Read All

Using tcpdump to capture network traffic on the command line

By Joao

To listen for traffic and write to stdout:
tcpdump -i -n -A expression

  • -i The interface id to listen on ( run tcpdump -D to get a list of available interfaces )
  • -n Don’t convert host addresses to names (avoid dns resolution)
  • -A Print packets in ASCII, excluding link level headers. Use -X for both hex and ASCII printout.

See man pcap-filter for a full description of ‘expression’
Examples include:
tcpdump -i 11 -n -A -s 65535 port 80
tcpdump -i 11 -n -A -s 65535 dst host

Other usefull flags:
-w write packets to a file which can later be replayed with -r

categoriaTechnology commentoNo Comments dataSeptember 7th, 2011
Read All

Sendmail from/to example

By Joao

Sending an email from the command line using sendmail with the send/to fields set:

sendmail -v -f sender@zonalivre.org recipient@zonalivre.org
Subject: Test Email
Email content here


categoriaTechnology commentoNo Comments dataAugust 16th, 2011
Read All

Turn off blinking/visual bell in gnome 3

By Joao

When using a terminal, tab auto completion makes the whole screen blink (aka visual bell). I find this annoying as hell. To work around it:

Start gconf-editor
Navigate to /apps/metacity/general
Either turn off “visual_bell”, or change “visual_bell_type” from “fullscreen” to “frame_flash”

categoriaTechnology commentoNo Comments dataJuly 18th, 2011
Read All

winetricks fails when installing vcrun2010

By Joao

You run
winetricks vcrun2010

But get the message:

Using native,builtin override for following DLLs: msvcr100
Executing early_wine regedit c:\winetrickstmp\override-dll.reg
Executing wget -O msxml3.msi -nd -c –read-timeout=300 –retry-connrefused –header Accept-Encoding: gzip,deflate http://download.microsoft.com/download/8/8/8/888f34b7-4f54-4f06-8dac-fa29b19f33dd/msxml3.msi
–2011-03-12 23:10:19– http://download.microsoft.com/download/8/8/8/888f34b7-4f54-4f06-8dac-fa29b19f33dd/msxml3.msi
Resolving download.microsoft.com…,
Connecting to download.microsoft.com||:80… connected.
HTTP request sent, awaiting response… 404 Not Found
2011-03-12 23:10:20 ERROR 404: Not Found.

Note: command ‘wget -O msxml3.msi -nd -c –read-timeout=300 –retry-connrefused –header Accept-Encoding: gzip,deflate http://download.microsoft.com/download/8/8/8/888f34b7-4f54-4f06-8dac-fa29b19f33dd/msxml3.msi’ returned status 8. Aborting.
vcrun2010 failed

The VC2010 runtime redistributable setup needs to load msxml3. winetricks tries to download it from a location in the microsoft.com website where it is no longer available. Instead, search the web for the file “msxml3.msi” and edit winetricks to point to it, eg:

vi winetricks

Find the load_msxml3 function, and replace the download location:


w_download msxml3 http://download.microsoft.com/download/8/8/8/888f34b7-4f54-4f06-8dac-fa29b19f33dd/msxml3.msi d4c2178dfb807e1a0267fce0fd06b8d51106d913


w_download msxml3 ftp://ftp.uni-rostock.de/pub/tools/microsoft/XML/US/msxml3.msi

categoriaTechnology commento4 Comments dataMarch 13th, 2011
Read All