Warning: preg_replace(): Compilation failed: escape sequence is invalid in character class at offset 4 in /home/customer/www/theunixtips.com/public_html/wp-content/plugins/resume-builder/includes/class.resume-builder-enqueues.php on line 59

bash : run command on find results

Unix find command allows user to execute a command on the results by using -exec command. For example see below. {} get replaced by filename, Make sure to escape {} and ;.

find . -type f -exec ls -l {} ;

This triggers ls -l on all the files that were found. I used this with -maxdepth (how deep directory structure to examine) and -mtime (last modified time) to cleanup old files as below.

find /var/log -type f -mtime +30 -maxdepth 0 -exec rm -f {} ;

Continue reading →

perl : Set different TimeZone for script

Here is how to set the timezone inside a perl script. A use case is when the application is communicating with some server in a different timezone and you want to log the time in the timezone of the other end instead of the timezone where this script is running.

$ENV{TZ} = ':/usr/share/zoneinfo/US/Eastern';

Hardware : Dell GX620 SFF HTPC Bootup problem due to burned up capactiors

I added a PCI Express Video card to my Dell GX620 Small Form Factor desktop system and connected it to my Television. One small thing that I completely missed out was the amount of heat that gets generated in such a small confined spot with no outlet for that hot air. And one day it refused to boot up. It will not go to POST. The power LED will come Green, fan on the processor will come on and then switch off. After 3-4 retries it will boot up and display “A Thermal Event has occurred“. But I did not pay attention to that. Silly me. After couple of days it started to take about 20 tries. That’s when I started to search around.

There were so many posts but no real answers. But there was a common lead badmouthing Dell and other PC manufacturers that for saving cost they have used cheap capacitors that burn up.  In my case that was certainly not true. The system had best that market has to offer (Rubycon capacitors) but it was me who managed to burn them off. I got the final on it when I stumbled upon BadCaps.net. A very good website with information on what exactly was going on. So I opened up the system, took out the hard-disk and right under it on the mother board were four capacitors (2200 µF, 6.3V, 10mm) that were popped. The heat from Video card fried the poor chaps as they were too close.

Continue reading →

perl : Create unix time from readable time

Many a times you may need to convert the human readable time into the Unix time. When all the information is passed to “mktime” it returns the unixtime. And to reverse it simply use “localtime”. Here is the example.

use POSIX;
use strict;
use warnings;

my $sec = 6;
my $min = 7;
my $hour = 8;
my $day = 9;
my $mon = 10 - 1;
my $year = 2004 - 1900;
my $wday = 0;
my $yday = 0;

my $unixtime = mktime ($sec, $min, $hour, $day, $mon, $year, $wday, $yday);
print "$unixtimen";

my $readable_time = localtime($unixtime);
print "$readable_timen";

Found at http://www.adp-gmbh.ch/perl/posix/convert_time.html

bash : brace expansion for automatic substitution

Bash expands a list of strings separated by commas with in braces to a list of strings separated by spaces. For example

[unixite@theunixtips:~/> echo 111-{aa,bb,cc}+{xx,yy,zz}-222
111-aa+xx-222 111-aa+yy-222 111-aa+zz-222 111-bb+xx-222 111-bb+yy-222 111-bb+zz-222 111-cc+xx-222 111-cc+yy-222 111-cc+zz-222

There should not be any space between suffix/prefix and the start/end bracket. Otherwise it is considered as a separate list. Now coming to a real world example where you can make use of this.

mv process.log{,.old} #This will move process.log to process.log.old
mv process.log.{old,oldest} #This will move process.log.old to process.log.oldest

Sendmail : Configure outgoing relay server

Edit following in /etc/mail/sendmail.cf and add the name of your outgoing/relaying mailhost. Ensure that the relay server is accepting your email first.

# "Smart" relay host (may be null)

e.g. if the outgoing relay is mailhost.xyzserver.com sendmail configuration should look like following.

# "Smart" relay host (may be null)
DS mailhost.xyzserver.com

After that restart the sendmail.

/etc/init.d/sendmail stop
/etc/init.d/sendmail start