Resman says hi.

Scriptlets

Petits bouts de code à usage divers.

watchline.pl - Permet de surveiller les changements d'une ligne dans un fichier
#!/usr/bin/perl
 
unless( $ARGV[1] ) {
    print "Usage : $O <fichier> <pattern> [intervalle]\nIntervalle par défaut = 1s.\n";
    exit;
}
my $interval = $ARGV[2]?$ARGV[2]:1;
my $l = "";
while(1) {
    open my $fd, "< $ARGV[0]";
    while(<$fd>) { last if /$ARGV[1]/; }
    chomp;
    if( $_ ne $l ) {
        my $t = `date +[%H:%M:%S]`;
        chomp $t;
        print "$t ", $l = $_, "\n";
    }
    close $fd;
    sleep $interval;
}

mks - Crée un fichier exécutable et y place le shebang en fonction de l'extension
#!/bin/sh
 
if [ $# -ne 1 ]; then
    echo "Usage : mks <nom du script>" && exit 1
fi
if [ -e "$1" ]; then
    echo "$1 existe déjà." && exit 1
fi
> "$1"
chmod +x "$1"
if [ "${1: -3}" == ".pl" ]; then
    echo -e "#!/usr/bin/perl\n\n" > "$1"
fi
if [ "${1: -3}" == ".sh" ]; then
    echo -e "#!/bin/sh\n\n" > "$1"
fi
   $EDITOR "$1"

man - CGI pour afficher une page man avec liens
#!/usr/bin/perl
 
$s = "";
$p = "man";
#print $ENV{QUERY_STRING};
($p) = $ENV{QUERY_STRING} =~ m!p=([a-z._]+)!;
($s) = $ENV{QUERY_STRING} =~ m!s=(.)!;
 
open $fd, "man $s $p 2>&1 |";
@l = <$fd>;
$l = join "", @l;
$l =~ s!(.)\010\1!<b>\1</b>!sg;
$l =~ s!_\010(.)!<u>\1</u>!sg;
$l =~ s!</(.+)><\1>!!sg;
$l =~ s!(</.>)?([a-z._]+)(</.>)?\((.)\)!< a href=man?p=\2&s=\4>\1\2\3\(\4\)</a>!sg;
 
print <<END;
Content-type: text/html\n
<html>
<head><title>$p($s)</title></head>
<body><form><input type=text name=p><input type=submit value=man></form>
<pre>$l</pre></body></html>
END

iptables chains diagram
                                        Network
                             -----------+-----------
                                        |
                                +-------+------+
                                |    mangle    |
                                |  PREROUTING  | <- MARK REWRITE
                                +-------+------+
                                        |
                                +-------+------+    Policy rule database
                                |     PRDB     | <- controlled by ip rule
                                +-------+------+
                                        |
                                +-------+------+
                                |      nat     |
                                |  PREROUTING  | <- DEST REWRITE
                                +-------+------+
                                        |
                 packet is for  +-------+------+ packet is for
                 this address   |     INPUT    | another address
                 +--------------+    ROUTING   +---------------+
                 |              +--------------+               |
         +-------+------+                                      |
         |    filter    |                                      |
         |    INPUT     |                                      |
         +-------+------+                                      |
                 |                                             |
         +-------+------+                                      |
         |    Local     |                                      |
         |   Process    |                                      |
         +-------+------+                                      |
                 |                                             |
         +-------+------+                                      |
         |    OUTPUT    |                              +-------+-------+
         |    ROUTING   |                              |    filter     |
         +-------+------+                              |    FORWARD    |
                 |                                     +-------+-------+
         +-------+------+                                      |
         |    mangle    |                                      |
         |    OUTPUT    | MARK REWRITE                         |
         +-------+------+                                      |
                 |                                             |
         +-------+------+                                      |
         |     nat      |                                      |
         |    OUTPUT    | DEST REWRITE                         |
         +-------+------+                                      |
                 |                                             |
         +-------+------+                                      |
         |    filter    |                                      |
         |    OUTPUT    |                                      |
         +-------+------+                                      |
                 |                                             |
                 |                                             |
                 +----------------+       +--------------------+
                                  |       |
                                  |       |
                               +--+-------+---+ selection of the output
                               |              | interface,
                               |  FORWARDING  | selection of the next hop,
                               +-------+------+ encapsulation, etc.
                                       |
                                       |
                               +-------+------+
                               |     nat      |
                               | POSTROUTING  | SOURCE REWRITE
                               +-------+------+
                                       |
                                       |
                               +-------+------+
                               |   TRAFFIC    |
                               |    QUEUE     | <- controlled by tc
                               +-------+------+
                                       |
                                       |
                            -----------+-----------
                                    Network

Comments

Add a new comment :
Name :
Comment :

Answer the following question : Which is the smallest, a peanut or a kettle ?