Friday, September 25, 2009

How to open port 80/http and 443/https on Fedora Core 10

Login as root


# vi /etc/sysconfig/iptables

Add these lines

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 443 -j ACCEPT

Restart iptables


# /etc/init.d/iptables restart


Wednesday, August 12, 2009

Ignore Ctrl-C in perl and shell scripts

Perl

Add to code :
$SIG{'INT'} = 'IGNORE';


Shell scripts

Add to code :
trap "" 1 2 3 15

Simple Logging in Perl

Set a Logging Variable

my $logging=1

Conditionally Open and Close the Logfile

At the earliest reasonable time, open the logfile in append mode:
if($logging){open FILE , ">>./my.log";}
At the latest possible time, close the logfile
if($logging){close FILE};
Don't
forget to close the logfile as part of your error handling routines as
well. Perl cleans things up nicely for you, but there are always
exceptions to those kinds of rules.

Logging Subroutine

A simple subroutine to enable logging as follows:
sub logit{
if ($logging){
print FILE "$_[0]\n";
}
}
It
prints whatever it receives in the first parameter to the log file. If
you need to print something simple, just call "logit('text to log');"
and your log entry will be created.

Source : http://www.stevekallestad.com/blog/simple_logging_in_perl.html

Simple Logging in Perl

Set a Logging Variable

my $logging=1

Conditionally Open and Close the Logfile

At the earliest reasonable time, open the logfile in append mode:
if($logging){open FILE , ">>./my.log";}
At the latest possible time, close the logfile
if($logging){close FILE};
Don't
forget to close the logfile as part of your error handling routines as
well. Perl cleans things up nicely for you, but there are always
exceptions to those kinds of rules.

Logging Subroutine

A simple subroutine to enable logging as follows:
sub logit{
if ($logging){
print FILE "$_[0]\n";
}
}
It
prints whatever it receives in the first parameter to the log file. If
you need to print something simple, just call "logit('text to log');"
and your log entry will be created.

Source : http://www.stevekallestad.com/blog/simple_logging_in_perl.html

Friday, August 7, 2009

Perl : Check if directory is empty

Here is some perl code to do that

#!/usr/bin/perl -w

my $path="/var/tmp/zt/a";

opendir DIR, $path;
if(scalar(grep( !/^\.\.?$/, readdir(DIR))) == 0){
    printf("Dir empty\n");
}
else  {
    printf("Dir not empty\n");
}
closedir DIR;