RSS

  • YouTube
  • LinkedIn
  • Google

Archives for : December2015

Naming files using list from 0 to Z

Today I was coding some scripts and found a little trouble to use a defined pattern.

The pattern is to create files where the sequence starts in 0 (zero) and cannot be repeated until Z.

Example:

myfile0.ext, myfile1.ext, myfile2.ext, (...), myfile9.ext, myfileA.ext, myfileB.txt, (...), myfileZ.txt

Well, this is not a big trouble so I did use this code.

But $seq did not gave the expected value of 0 (zero) on first run. Instead, it was blank.

Debugging the variables, I saw that the while never evaluates to true. Attempting to reproduce on command line I saw that in_array($seq, $seqs); always return true. I tryed to use “”, “R” and no matter what value I used, still returning true.

So I change to use STRICT argument for in_array to true and works for ‘A’ through ‘Z’, but not for ‘0’ through ‘9’.

Damn… PHP is right, “0” is not strictly equals to 0. The Chr function return string and range('0', '9') creates an array with integer values.

So, I changed the approach to evaluate all values with STRICT, because I would like to create a nice and clean code without no other functions to be used.

This is the final code that I’m using:

How you can see, I changed the $seqs initial values from ‘0’ to your ASCII code and get back to your value that gave me an array with all values in string type.

See you!

PHP Comparison Error

Today, I was writing a script in PHP to be used in the command line when I came across unexpected behavior (at least on my part).
The script should receive three arguments, the last of them a list containing one or more numeric codes.
Trying to validate this last argument was getting a different result than imagined.
See the code snippet that I was using:

Continue Reading >>

How to fix date / time on Centos 6.X for your timezone even in logfiles

Today I came across a problem when using the Fail2ban that help me so much to keep my server online even under brute-force attack.

One of my filters were not barring the several attempts to authenticate to a my services although it was fine. I decided to increase the Findtime the common configuration and it began to block.

So it was time to understand why with a findtime down he couldn't spread. I began to check in detail the settings and I realized that even though I changed the time for my timezone to the official schedule of Brasilia, the logs continued to display the schedule in UTC. Suspected that it could be this and decided to change the schedule that is placed in the logs (/var/log/messages).

Bingo!

After the change, and confirm that the logs were using the same schedule that the reported in date changed the findtime to values which wanted and everything worked as expected.

Follow the recipe to change the schedule.

Timezone information are on file /etc/localtime and if he's not on what you want simply replaces him for what he wants and that is present in /usr/share/zoneinfo/. In my case, how I wish the schedule of Brasília, I used /usr/share/zoneinfo/America/Sao_Paulo.

Now just try using the date command and check the output should be something like:

Even after these changes, the logs will continue to have the time the old-fashioned way. To change this edit the file /etc/sysconfig/clock and add the following lines to also reflect your timezone.

In my case, I had to restart the server for the changes to surtissem effect but just restarting the rsyslog service already solve.

See you!.

How to fix LOCALE error on Debian Linux/Ubuntu

Today I had to look at the logs to an FTP server that runs under the pure-ftp and I realized that the timetables were all in UTC .
As I needed to send part of the logs to a third party that makes use of it and are not familiar with systems, could end up taking place some misunderstanding. I decided then that should keep the logs of all the applications on Brazilian time zone.
According to the documentation of the pure-ftp it uses environment variables to determine which will be the schedule included in the logs

Continue Reading >>