Get the Dell Service Tag number with Linux


[root@SERVER ~]# dmidecode | grep “Serial Number”
                Serial Number: 8HZZ42C

Publié dans Linux | Marqué avec , , , , , , , , , , , , | Laisser un commentaire

The Horrorist Live @ Paris 2008 04 01

All pictures available here:
https://www.crapules.com/gallery2/v/concerts/Horrorist/

20080401_Horro01.jpg

20080401_Horro02.jpg

Publié dans Photos Concerts | Marqué avec , , , , , , , , , , , , , , , , , , , , , , | Laisser un commentaire

JO: un journaliste de FR2 viré par des officiels chinois

Je ne suis pas fan de morandini, mais une vidéo intéressante lors de la flamme à paris:
Un journaliste de France2 qui filmait les manifestants et les officiels chinois c’est fait sortir par les officiels chinois qui visiblement demandaient à la police et obtenaient ce qu’ils voulaient.

Publié dans Vrac | Marqué avec , , , , , , , , , , , , , | Laisser un commentaire

Setup Sendmail without DNS

Configure Sendmail is not very funny.
In my case I have several box in a DMZ and i would like these box will be available to send email from my mail server. But sendmail need a valid MX reply to relay emails.
Without this valid MX you should have this error in the log file

Apr 4 15:46:32 SERVER-01 sendmail[2422]: [ID 801593 mail.info] m34DdKJC002400: to=,, delay=00:07:12, xdelay=00:00:00, mailer=relay, pri=240354, relay=mail, dsn=4.0.0, stat=Deferred: Name server: mailhost: host name lookup failure

When DNS doesn’t arrive for the party, sendmail gets mad.

How to solve this?

Linux (Redhat, Fedora, Debian)
First make sure you have the sendmail-cf package installed. Either install it and use yum/up2date/apt-get to get it.

rpm -Uvh sendmail-cf-8.13.1-3.fc2.i386.rpm

Next, add your smart relay host to your /etc/hosts file (your mail server)

192.168.1.100 mail mail.yourdomain.com

Go into /etc/mail/ and vi the sendmail.mc file. Add the following lines:

FEATURE(`accept_unresolvable_domains')dnl
FEATURE(`accept_unqualified_senders')dnl
FEATURE(nocanonify)
define(`confSERVICE_SWITCH_FILE', `/etc/mail/service.switch')dnl
define(`SMART_HOST',`mail')

Of course, replace the mail with the host you entered in your /etc/hosts file.
Now create a file in /etc/mail called service.switch and add the following:

root@SERVER-01 # cat /etc/mail/service.switch
hosts files
root@SERVER-01 #

Edit the submit.mc file in /etc/mail and add the following line:

define(`confDIRECT_SUBMISSION_MODIFIERS', `C')dnl

Now that we’re done making our file modifications, simply type make while in the /etc/mail directory.

Restart sendmail

/etc/init.d/sendmail restart

That’s it!

just need to test it:

mail -s test toto@mydomain.com &1 >> /dev/null

Solaris

More easy on solaris 10 (same thing on V8 and V9)
Edit the files /etc/mail/sendmail.cf and /etc/mail/submit.cf
and uncomment the following lines:

# service switch file (name hardwired on Solaris, Ultrix, OSF/1, others)
O ServiceSwitchFile=/etc/mail/service.switch

# hosts file (normally /etc/hosts)
O HostsFile=/etc/hosts
root@SERVER-01 # more service.switch
hosts files

don’t forget to setup your host file


127.0.0.1       localhost       SERVER-01.mydomain.com
192.168.1.100    mail    mail.mydomain.com

Check in your /etc/nsswitch.conf file the line « hosts » like this:


hosts:      files

Check in your sendmail conf file (main.cf, sendmail.cf, subsidiary.cf) your relay host is setup


# "Smart" relay host (may be null)
DSmail

In the same files replace the following lines


# pass to name server to make hostname canonical
R$* $| $*  $*          $: $2  $4
R$* $| $*                      $: $2

by


# pass to name server to make hostname canonical
R$* $| $*  $*           $: $2  $4
R$* $| $*                       $: $2

Be VERY carreful with the tabulations!

Just relaunch sendmail

svcadm refresh network/smtp:sendmail

And test again …

Publié dans Linux, Solaris | Marqué avec , , , , , , , , , , , , | 3 commentaires

recursive mass rename script

Hello,

here a little script called myrename.pl to mass rename all the file of a directory and all the sub-directory and all files.
I need this script to delete the space character in the filename

The script:


#!/usr/bin/perl
#
# Usage: rename perlexpr [files]

($regexp = shift @ARGV) || die "Usage:  rename perlexpr [filenames]\n";
#print "REGEXP :$regexp:\n";

if (!@ARGV) {
    @ARGV = ;
    chomp(@ARGV);
}


foreach $_ (@ARGV) {
    $old_name = $_;
    eval $regexp;
#    print "Regexp after :$regexp:\n";
    die $@ if $@;
####   rename($old_name, $_) unless $old_name eq $_;
    rename($old_name, $_) unless $old_name eq $_; #or
####    warn "Couldn't rename $old_name to $_: $!\n";
    print "$old_name ----> $_\n";
}

exit(0);


Using the script:


find ./ -print | tac | /usr/bin/myrename.pl '($file) = (m|.+/(.+)|); $file = $_ if (!defined($file));($newfile = $file) =~ s/ /_/g;$file2=quotemeta($file); s/$file2/$1$newfile/;'

Publié dans Linux | Laisser un commentaire

listing & zip Dir on the Fly

Hello,
Sometime I need to access my music from work.
To do this I have made a quick php script to print my private collection hosted on my own server and added a script to create archive file (.zip) on the fly.

J’ai développé une petite page php pour gerer ma musique sur mon server perso. Ce script me permet de créer un fichier zip a la volée pour chaque album que je veux prendre chez moi.

homelist

Prequesities:
you need the package zipArchives for php5
On Fedora:


yum install php-pecl-zip

On Debian


apt-get install php5-zip

Let me explain: if you go to https://www.crapules.com/test.zip this will create a test.zip file on the fly with all the content of https://www.crapules.com/test directory.
To do this you need to change your .htaccess file like this.

Le principe est simple. Lorsque un utilisateur utilise une URL avec une extension .zip dans certain répertoire, le script créer un fichier archive contenant l’intégralité du repertoire. Par exemple https://www.crapules.com/test.zip, créera un zip avec l’intégralité de https://www.crapules.com/test.
La première étape est de créer un fichier .htaccess dans ledit répertoire comme suit:


RewriteEngine On
Options +FollowSymlinks
RewriteCond %{REQUEST_URI} .zip$ [NC]
RewriteRule ^(.*).zip$ download.php?download=$1 [L]

This change will redirect all the link like
https://www.crapules.com/test.zip
in
https://www.crapules.com/download.php?download=test

Now you need to create a download.php in the same directory:
On crée un fichier download.php dans le même répertoire:


<?php
# download.php
# This script is an adaptation from the balupton's script from b2evolution.net.
# Thanks to him

function myDownloadFile ( $file_path, $content_type = NULL, $buffer_size = 20000 )
{    // Credits go out to; pechkin at zeos dot net - http://au3.php.net/manual/en/function.header.php#65667
    // Modified into function by balupton
    // A shitload of upgrade to this done by balupton
    // Modified by Pateretou to delete file after downloading

    if ( empty($content_type) )
        $content_type = 'application/force-download';

    // Define variables
    $fpath = $file_path;
    $fname = basename($file_path);
    $fsize = filesize($fpath);
    $bufsize = $buffer_size;

    if ( isset($_SERVER['HTTP_RANGE']) )
    {    // Partial download
        if( preg_match("/^bytes=(\\d+)-(\\d*)$/", $_SERVER['HTTP_RANGE'], $matches) )
        {    // Parsing Range header
            $from = $matches[1];
            $to = $matches[2];

            if( empty($to) )
            {
                $to = $fsize - 1;  // -1  because end byte is included
            }

            $content_size = $to - $from + 1;

            header("HTTP/1.1 206 Partial Content");
            header('Pragma: public');
            header('Cache-control: must-revalidate, post-check=0, pre-check=0');
            header('Expires: ' . gmdate('D, d M Y H:i:s') . ' GMT');
            header("Content-Range: $from-$to/$fsize");
            header("Content-Length: $content_size");
            header("Content-Type: $content_type");
            if ( $content_type == 'application/force-download' )
                header("Content-Disposition: attachment; filename=$fname");
            header("Content-Transfer-Encoding: binary");

           if(file_exists($fpath) && $fh = fopen($fpath, "rb"))
           {
               fseek($fh, $from);
               $cur_pos = ftell($fh);
               while($cur_pos !== FALSE && ftell($fh) + $bufsize addFile($dir.$file,$extdir.$file);
                    myCreateArchive($dir.$file.'/' , $zip, $extdir.$file.'/');

                }
                else
                {
                    $zip->addFile($dir."/".$file,$extdir.$file);
                }
            }
        }
        closedir($rs);
    }
    return true;
}

# Prepare variables
if ( !isset($_GET['download']) )
    exit('no download');
$download = $_GET['download'];

$this_dir_path = dirname(__FILE__);
$this_dir_path = realpath($this_dir_path);

$parent_dir_path = $this_dir_path.'/../';
$parent_dir_path = realpath($parent_dir_path);

$dir_path = $this_dir_path.'/'.$download;
$dir_path = realpath($dir_path);

if ( $this_dir_path && $parent_dir_path && $dir_path )
{    /* Ok, variables are set we can continue*/    }
else {
    exit('something went wrong...');
}

if ( substr($dir_path, 0, strlen($parent_dir_path)) === $parent_dir_path )
{    /* good */    }
else
    exit('stop hacking '."[$dir_path][$parent_dir_path]");

$file_path = $this_dir_path.'/'.$download.'.zip';

# Remove old file
if ( is_file($file_path) )
    unlink($file_path);

# Create Zip
$zip = new ZipArchive();
if ( $zip->open($file_path, ZIPARCHIVE::CREATE) !== TRUE )
        exit("cannot open \n");

# Add file to Zip
myCreateArchive($dir_path, $zip);

$zip->close();

# Download
echo "file_path:$file_path
\n"; myDownloadFile($file_path, 'archive/zip'); die;

You can try you script with the following url:
http://youwebsite.com/download.php?download=test to download the content of your « test » directory for example.
If it’s work, you can test your .htaccess file with the url
http://youwebsite.com/test.zip

Now you can do a cute index page like this:



Crapules
Crapules.com logo

Crapules.com Listing Access

Please be patient if you try to DL a ZIP file. It's took take more than 40 secondes

<? $myDirectory = opendir("."); while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } closedir($myDirectory); $indexCount = count($dirArray); // sort case unsensitive usort($dirArray, "strcasecmp" ); // print print("\n"); print("\n"); for($index=0; $index < $indexCount; $index++) { $extension = array_pop(explode(".", $dirArray[$index])); if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files if ($extension != "php") { print(""); print(""); print(""); print(""); print("\n"); } } } print("\n"); ?>
Logo designed by [A]ura. ©2004-2008 Crapules.com. All Rights Reserved.
_uacct = "UA-3653212-1"; urchinTracker();
Publié dans Linux, Vrac | Marqué avec | Laisser un commentaire

Force (W)SUS to update

Below a batch to force WSUS , windows update to update automaticaly.


@echo off
Echo This batch file will Force the Update Detection from the AU client:
Echo 1. Stops the Automatic Updates Service (wuauserv)
Echo 2. Deletes the LastWaitTimeout registry key (if it exists)
Echo 3. Deletes the DetectionStartTime registry key (if it exists)
Echo 4. Deletes the NextDetectionTime registry key (if it exists)
Echo 5. Restart the Automatic Updates Service (wuauserv)
Echo 6. Force the detection
Pause
@echo on
net stop wuauserv
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v LastWaitTimeout /f
REG DELETE "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v DetectionStartTime /f
Reg Delete "HKLM\Software\Microsoft\Windows\CurrentVersion\WindowsUpdate\Auto Update" /v NextDetectionTime /f
net start wuauserv
wuauclt /detectnow
@echo off
Echo This AU client will now check for the Updates on the Local WSUS Server.
Pause

Publié dans Windows | Marqué avec | Laisser un commentaire

resize, add border&watermark

Hello,

Imagemagick is a very powerfull program to modify picture with a simple comand line.
For example, we can write a script to automatically resize, add a border and watermark to many picture in the same directory.


#/bin/sh
for img in `ls *.jpg`
do
convert $img -resize 20% rez_$img
convert -bordercolor "#000000" -border 2x2 -bordercolor "#FFFFFF" -border 4x4 -bordercolor "#000000" -border 2x2 rez_$img border_$img
convert border_$img -font /usr/share/fonts/default/ghostscript/bchri.pfa -fill white -pointsize 16 -draw "gravity southeast text 10,7 '(c) Vargas Emmanuel http://www\
.crapules.com'" final_$img
/bin/rm -f rez_$img
/bin/rm -f border_$img
done

Publié dans Linux, Vrac | Marqué avec | Laisser un commentaire

RIP Linux Server

First Time I need to definitively shutdown a Production Linux Server.

RIP.

cro_RIP

Publié dans Vrac | Marqué avec | Laisser un commentaire

Solaris tips

Solaris tips

recursively Search keywords


find . -type f -print | xargs grep chaine_a_chercher

Reboot


shutdown -i 6 -g 2 -y "bye"

List the files in current directory sorted by size


ls -l | grep ^- | sort -nr

Delete blank lines in a file ?


cat sample.txt | grep -v '^$' > new_sample.txt

Display the Disk Usage of file sizes under each directory in currentDirectory ?


du -k * | sort –nr
or
du –k . | sort -nr

Set the Display automatically for the current new user ?


export DISPLAY=`eval 'who am i | cut -d"(" -f2 | cut -d")" -f1?`

List some Hot Keys for bash shell ?


Ctrl+l – Clears the Screen.
Ctrl+r – Does a search in previously given commands in shell.
Ctrl+u - Clears the typing before the hotkey.
Ctrl+a – Places cursor at the beginning of the command at shell.
Ctrl+e – Places cursor at the end of the command at shell.
Ctrl+d – Kills the shell.
Ctrl+z – Places the currently running process into background.

How do you find out drive statistics ?


iostat -E

Display top ten largest files/directories ?


du -sk * | sort -nr | head

How much space is used for users in kilobytes ?


quot -af

Display Ethernet Address arp table ?


arp -a

Display the no.of active established connections to localhost ?


netstat -a | grep EST

Display the state of interfaces used for TCP/IP traffice ?


netstat -i

Show the working directory of a process ?


pwdx 

Display the processes current open files ?


pfiles 

Alternative for top command ?


prstat -a
Publié dans Solaris | Marqué avec | Laisser un commentaire