Distinguish uploading files when uploading via FTP using ProFTPd

ftp

When uploading a large file, if you want to work within a directory full of files, you will find that it is quite difficult to ignore the ones that are being processed.

If you’re on the actual server itself, you can use ftpwho. http://linux.die.net/man/1/ftpwho
This is shows the current active processlist of files being uploaded by FTP.

Alternatively, and I found this by far the easiest way to distinguish between a file currently uploading and a file that is already uploaded. In comes “HiddenStores”:
http://www.proftpd.org/docs/directives/linked/config_ref_HiddenStores.html

This will mark a file with a ‘.in.’ at the beginning of the file name, so that you can easily identify a file that is being worked on at that point in time.

Stop Mail popping up on Mac OSX when using iCal as your Mac Calendar Tool

mac osx

There is truly only one way to reverse this problem – if it truly is a problem for you. I was frustrated that whenever I’d receive an alert from iCal, I’d get a popup that would then proceed to open Mac Mail, which I don’t use.

This is a nasty workaround, but basically sets a permission on the Mail application so that it is no longer readable or executable.

Firstly, to turn off the Mail notifications:
sudo chmod 000 /Applications/Mail.app/Contents/MacOS/Mail

Secondly, to re-enable:
sudo chmod 755 /Applications/Mail.app/Contents/MacOS/Mail

Perl array multisorting

perl

PHP includes a native function array_multisort. I miss that in Perl. There’s not as many native functions in Perl to work on arrays, so for a critical project I needed to come up with a different solution.

I decided at first to use just one array, for the same purpose.

Let’s say I have the following arrays:

1 – some_string
2 – some_other_string
4 – some_other_random_string
3 – some_other_random_string_again

And I wanted to order them by the first array, with the numbers. Firstly, you need to check that warnings are turned off in Perl, as you’ll often get “warning is numeric” when running your program.

In the end, I created a new array, let’s called it ‘sorted instances’

my @sorted_instances = ();

# When looping through my previous results, push to the new array, where $1 and $2 match the previous two arrays. #
foreach (@unsorted_instances) {
push @sorted_instances, “$1,$2”;
}

Now the magic which sorts the arrays:
@sorted_instances = sort { $a <=> $b } @sorted_instances;

Confirm it works well:
foreach (@sorted_instances) {
print $_;
print “\n”;
}

Messy, but it works.

puppet failures due to “dnsdomainname: Unknown host”

linux, puppet, selinux

When I was trying to start puppet, I had the following message:
[root@m03 puppet]# service puppet start
Starting puppet: dnsdomainname: Unknown host
dnsdomainname: Unknown host

Even though puppet started successfully. I checked my /etc/hosts file as puppet looks up DNS from there, everything looked fine. I also disabled selinux as that had been recommended on another blog. That might work for you, but didn’t do much for me.

Trying to sign my certificate was proving to be the same issue as well, rendering my puppet setup completely useless:
/usr/sbin/puppetd –waitforcert 30
dnsdomainname: Unknown host
dnsdomainname: Unknown host

I decided to check on the puppet master to see if my signature request had successfully hit the master:
puppet cert list –all | grep -i m03
…but no joy there.

When the dnsdomainname error comes up, the obvious answer is that the DNS is not resolving and it turns out that my puppet install is using an extra DNS entry to connect to the master. I compared an entry on another machine in /etc/resolv.conf, added that to the new machine; ran:
/usr/sbin/puppetd –waitforcert 30

…then the catalog ran successfully.

Downloading the JDK from Oracle’s page from the command line

java, jdk, oracle

Since earlier in 2012, Oracle included a non-optional requirement that you need to Accept the T&C’s when downloading the JDK from their site. As you already agree the terms and conditions once you actually install or run the bin file, it isn’t absolutely necessary.

There’s a way around it using cookies, and I was able to download the file I needed when including the following cookie:

wget –no-cookies –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F”http://download.oracle.com/otn-pub/java/jdk/6u37-b06/jdk-6u37-linux-i586.bin

In PHP, converting Shift-JIS into UTF-8

php

Still some websites use Shift-JIS character sets instead of UTF-8. To convert Shift-JIS Japanese text into a more friendly UTF-8 format, I needed to include the following in my PHP code:

$converted_string = iconv(‘shift-jis‘,’utf-8‘.’//TRANSLIT’,$string_to_convert);

Of course it’s also possible to store the data in MySQL using a BLOB data type, but I wanted to use standard text/varchar, and make it searchable. This worked well.

The same can also be applied for converting the other way, when needing to convert UTF-8 to Shift_JIS.

$converted_string = iconv(‘utf8‘,’shift-jis‘.’//TRANSLIT’,$string_to_convert);

Installing jdk6+ and setting update-alternatives for java

java

wget –no-cookies –header “Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F” http://download.oracle.com/otn-pub/java/jdk/6u37-b06/jdk-6u37-linux-i586.bin
chmod a+x jdk-6u37-linux-i586.bin
./jdk-6u37-linux-i586.bin
mv jdk1.6.0_37/ java-6-oracle
mv java-6-oracle/ /usr/lib
sudo mkdir /usr/lib/jvm
cd /usr/lib
mv java-6-oracle/ jvm
sudo update-alternatives –install “/usr/bin/java” “java” “/usr/lib/jvm/java-6-oracle/bin/java” 1
sudo update-alternatives –install “/usr/bin/javac” “javac” “/usr/lib/jvm/java-6-oracle/bin/javac” 1
sudo update-alternatives –install “/usr/bin/javaws” “javaws” “/usr/lib/jvm/java-6-oracle/bin/javaws” 1