<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>
<channel>
	<title>blog.nicolas.pawlak.fr &#187; Programmation</title>
	<atom:link href="http://blog.nicolas.pawlak.fr/categories/programmation/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.nicolas.pawlak.fr</link>
	<description>Tux ne sait pas voler, c&#039;est normal : ce n&#039;est pas un pingouin...</description>
	<lastBuildDate>Sun, 31 Jul 2011 14:56:24 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>Script shell vérifiant la disponibilité d&#8217;un nom de domaine</title>
		<link>http://blog.nicolas.pawlak.fr/2011/07/11/script-shell-verifiant-la-disponibilite-dun-nom-de-domaine/</link>
		<comments>http://blog.nicolas.pawlak.fr/2011/07/11/script-shell-verifiant-la-disponibilite-dun-nom-de-domaine/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 21:15:27 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[bash]]></category>
		<category><![CDATA[disponible]]></category>
		<category><![CDATA[domaine]]></category>
		<category><![CDATA[nom]]></category>
		<category><![CDATA[script]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=1442</guid>
		<description><![CDATA[Un petit script pour déterminer si un nom de domaine est libre ou déjà déposé. Les serveurs whois des différents registres de premier niveau renvoyant des réponses structurées différemment, il faut déterminer pour chaque TLD la réponse-type correspondant à un nom de domaine libre et l&#8217;inclure dans le script. Voici ce que retourne une requête [...]]]></description>
			<content:encoded><![CDATA[<p>Un petit script pour déterminer si un <a href="http://fr.wikipedia.org/wiki/Nom_de_domaine" title="nom de domaine" target="_blank">nom de domaine</a> est libre ou déjà déposé. </p>
<p>Les serveurs <a href="http://fr.wikipedia.org/wiki/Whois" title="whois" target="_blank">whois</a> des différents <a href="http://fr.wikipedia.org/wiki/Registre_(Noms_de_domaine)" title="registres" target="_blank">registres de premier niveau</a> renvoyant des réponses structurées différemment, il faut déterminer pour chaque <a href="http://fr.wikipedia.org/wiki/Domaine_de_premier_niveau" title="TLD" target="_blank">TLD</a> la réponse-type correspondant à un nom de domaine libre et l&#8217;inclure dans le script. </p>
<p>Voici ce que retourne une requête whois sur &laquo;&nbsp;domainequinexistesurementpas.fr&nbsp;&raquo; :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[root@pc-linux]# whois domainequinexistesurementpas.fr
[Requête en cours whois.nic.fr]
[whois.nic.fr]
%%
%% This is the AFNIC Whois server.
%%
%% complete date format : DD/MM/YYYY
%% short date format    : DD/MM
%% version              : FRNIC-2.5
%%
%% Rights restricted by copyright.
%% See http://www.afnic.fr/afnic/web/mentions-legales-whois_en
%%
%% Use '-h' option to obtain more information about this service.
%%
%% [XX.XX.XX.XX REQUEST] &gt;&gt; domainequinexistesurementpas.fr
%%
%% RL Net [##########] - RL IP [#########.]
%%
&nbsp;
%% No entries found in the AFNIC Database.</pre></div></div>
<p>A présent, la même requête sur &laquo;&nbsp;domainequinexistesurementpas.it&nbsp;&raquo; :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">[root@pc-linux]# whois domainequinexistesurementpas.it
[Requête en cours whois.nic.it]
[whois.nic.it]
Domain:             domainequinexistesurementpas.it
Status:             AVAILABLE</pre></div></div>
<p>Les deux réponses sont totalement différentes (&laquo;&nbsp;No entries found in the AFNIC Database&nbsp;&raquo; pour le .fr, &laquo;&nbsp;Status: AVAILABLE&nbsp;&raquo; pour le .it). Il est donc indispensable de prendre en compte, pour chaque TLD, la réponse-type correspondant à un nom de domaine libre.</p>
<p>En cas d&#8217;interrogation sur un TLD qui n&#8217;a pas été prévu dans le script, ce dernier retourne : &laquo;&nbsp;TLD NON PRIS EN COMPTE&nbsp;&raquo;.</p>
<p>Une particularité du script : placer dans une variable dans une autre variable. Cette particularité apparaît au moment de filtrer la réponse avec la réponse-type correspondant au TLD : la commande <em>grep</em> doit prendre en paramètre le contenu de la variable correspondant à la réponse-type du TLD, mais le nom de cette variable n&#8217;est pas fixe.</p>
<p><strong>Le script :</strong></p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># On place dans une variable le TLD du domaine interrogé.</span>
<span style="color: #666666; font-style: italic;"># Le . est remplacé par _ (cas du .co.uk notamment) pour des raisons de noms de variables.</span>
<span style="color: #007800;">tld</span>=<span style="color: #000000; font-weight: bold;">`</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #007800;">$1</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">2</span>- <span style="color: #660033;">-d</span> . <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s/\./_/&quot;</span><span style="color: #000000; font-weight: bold;">`</span>
&nbsp;
<span style="color: #666666; font-style: italic;"># On place pour chaque TLD la réponse-type d'un domaine libre dans une variable.</span>
<span style="color: #666666; font-style: italic;"># La variable porte le nom du TLD, avec le _ remplaçant le . si nécessaire.</span>
<span style="color: #007800;">fr</span>=<span style="color: #ff0000;">&quot;No entries found&quot;</span>
<span style="color: #007800;">be</span>=<span style="color: #ff0000;">&quot;Status:      FREE&quot;</span>
<span style="color: #007800;">ch</span>=<span style="color: #ff0000;">&quot;We do not have an entry&quot;</span>
<span style="color: #007800;">de</span>=<span style="color: #ff0000;">&quot;Status: free&quot;</span>
<span style="color: #007800;">it</span>=<span style="color: #ff0000;">&quot;Status:             AVAILABLE&quot;</span>
<span style="color: #007800;">pl</span>=<span style="color: #ff0000;">&quot;No information available&quot;</span>
<span style="color: #007800;">pt</span>=<span style="color: #ff0000;">&quot;no match&quot;</span>
<span style="color: #007800;">fi</span>=<span style="color: #ff0000;">&quot;Domain not found&quot;</span>
<span style="color: #007800;">no</span>=<span style="color: #ff0000;">&quot;No match&quot;</span>
<span style="color: #007800;">nl</span>=<span style="color: #ff0000;">&quot;is free&quot;</span>
<span style="color: #007800;">dk</span>=<span style="color: #ff0000;">&quot;No entries found&quot;</span>
<span style="color: #007800;">ru</span>=<span style="color: #ff0000;">&quot;No entries found&quot;</span>
<span style="color: #007800;">at</span>=<span style="color: #ff0000;">&quot;nothing found&quot;</span>
<span style="color: #007800;">co_uk</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
<span style="color: #007800;">net_uk</span>=<span style="color: #ff0000;">&quot;Not match for&quot;</span>
<span style="color: #007800;">org_uk</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
<span style="color: #007800;">uk</span>=<span style="color: #ff0000;">&quot;Error for&quot;</span>
<span style="color: #007800;">com</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
<span style="color: #007800;">net</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
<span style="color: #007800;">org</span>=<span style="color: #ff0000;">&quot;NOT FOUND&quot;</span>
<span style="color: #007800;">info</span>=<span style="color: #ff0000;">&quot;NOT FOUND&quot;</span>
<span style="color: #007800;">biz</span>=<span style="color: #ff0000;">&quot;Not found&quot;</span>
<span style="color: #007800;">ws</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
<span style="color: #007800;">edu</span>=<span style="color: #ff0000;">&quot;No Match&quot;</span>
<span style="color: #007800;">xxx</span>=<span style="color: #ff0000;">&quot;No match for&quot;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$1</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;PARAMETRE MANQUANT&quot;</span>
<span style="color: #000000; font-weight: bold;">else</span>
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #007800;">$2</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${!tld}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #666666; font-style: italic;"># Aucune variable n'est nommée comme le TLD : pas de réponse-type</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;TLD NON PRIS EN COMPTE&quot;</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                        <span style="color: #666666; font-style: italic;"># On filtre la réponse du whois avec la réponse-type du TLD.</span>
                        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #660033;">-z</span> <span style="color: #ff0000;">&quot;<span style="color: #780078;">`whois $1 | grep &quot;${!tld}&quot;`</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
                                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;ENREGISTRE&quot;</span>
                        <span style="color: #000000; font-weight: bold;">else</span>
                                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;LIBRE&quot;</span>
                        <span style="color: #000000; font-weight: bold;">fi</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;PARAMETRE EN TROP&quot;</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>
<p>Le script en action :</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>pc-linux<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ./dispo_ndd.sh domaine.fr</span>
ENREGISTRE
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>pc-linux<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ./dispo_ndd.sh domaine-existepas.fr</span>
LIBRE
<span style="color: #7a0874; font-weight: bold;">&#91;</span>root<span style="color: #000000; font-weight: bold;">@</span>pc-linux<span style="color: #7a0874; font-weight: bold;">&#93;</span><span style="color: #666666; font-style: italic;"># ./dispo_ndd.sh domaine.ca</span>
DOMAINE NON DISPONIBLE</pre></div></div>
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2011/07/11/script-shell-verifiant-la-disponibilite-dun-nom-de-domaine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Script de relance automatique du serveur SSH</title>
		<link>http://blog.nicolas.pawlak.fr/2010/09/21/script-de-relance-automatique-du-serveur-ssh/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/09/21/script-de-relance-automatique-du-serveur-ssh/#comments</comments>
		<pubDate>Tue, 21 Sep 2010 18:00:53 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[config]]></category>
		<category><![CDATA[dedibox]]></category>
		<category><![CDATA[dédié]]></category>
		<category><![CDATA[ovh]]></category>
		<category><![CDATA[relance]]></category>
		<category><![CDATA[restart]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[serveur]]></category>
		<category><![CDATA[service]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[sshd]]></category>
		<category><![CDATA[start]]></category>
		<category><![CDATA[stop]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=1267</guid>
		<description><![CDATA[Lorsque l&#8217;on administre un serveur à distance sans accès physique sur la machine, bien souvent, l&#8217;accès au serveur tient à un fil : celui du SSH. Si, pour une raison ou une autre, le serveur SSH s&#8217;arrête&#8230; les ennuis commencent pour l&#8217;administrateur et les utilisateurs. Même si les connexions SSH actives ne sont pas interrompues [...]]]></description>
			<content:encoded><![CDATA[<p>Lorsque l&#8217;on administre un serveur à distance sans accès physique sur la machine, bien souvent, l&#8217;accès au serveur tient à un fil : celui du <a href="http://fr.wikipedia.org/wiki/SSH">SSH</a>. Si, pour une raison ou une autre, le serveur SSH s&#8217;arrête&#8230; les ennuis commencent pour l&#8217;administrateur et les utilisateurs.</p>
<p>Même si les connexions SSH actives ne sont pas interrompues lors de l&#8217;arrêt du serveur (à condition de ne pas tout stopper avec un <a href="http://pwet.fr/man/linux/commandes/killall"><i>killall</i></a> !), il suffit d&#8217;un peu de malchance pour que celles-ci le soient : un plantage de votre système, une coupure électrique, une déconnexion de votre <a href="http://fr.wikipedia.org/wiki/Fournisseur_d%27acc%C3%A8s_%C3%A0_Internet">FAI</a> juste après l&#8217;arrêt du serveur SSH et vous voilà coincé à la porte de votre serveur distant.</p>
<p>Pour éviter cela, j&#8217;ai imaginé un script qui vérifierait régulièrement l&#8217;état du serveur SSH et le relancerait si besoin, avec restauration d&#8217;une sauvegarde du fichier <a href="http://pwet.fr/man/linux/formats/sshd_config">sshd_config</a> en cas d&#8217;échec lors du redémarrage. Ce script est évidemment à placer dans la <a href="http://fr.wikipedia.org/wiki/Crontab">crontab</a> d&#8217;un utilisateur ayant les droits requis pour travailler dans le répertoire de configuration de SSH et redémarrer le service&#8230; c&#8217;est à dire <a href="http://fr.wikipedia.org/wiki/Utilisateur_root"><i>root</i></a>, pour faire simple.</p>
<p><strong>Attention :</p>
<p>- Vérifiez bien votre configuration pour les variables déclarées en entête du fichier. Par exemple, le service se nomme &laquo;&nbsp;ssh&nbsp;&raquo; sur Debian / Ubuntu, et &laquo;&nbsp;sshd&nbsp;&raquo; sur Red Hat / Fedora.</p>
<p>- Testez le script sur un environnement de test dans un premier temps, pour éviter de faire des erreurs sur un environnement de production.</strong></p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
&nbsp;
<span style="color: #007800;">n_service</span>=<span style="color: #ff0000;">&quot;ssh&quot;</span>                      <span style="color: #666666; font-style: italic;"># Nom du service</span>
<span style="color: #007800;">f_exe</span>=<span style="color: #ff0000;">&quot;/usr/sbin/sshd&quot;</span>               <span style="color: #666666; font-style: italic;"># Exécutable du service</span>
<span style="color: #007800;">f_origine</span>=<span style="color: #ff0000;">&quot;/etc/ssh/sshd_config&quot;</span>     <span style="color: #666666; font-style: italic;"># Fichier de configuration actuelle</span>
<span style="color: #007800;">f_secours</span>=<span style="color: #ff0000;">&quot;/var/scripts/sshd_config&quot;</span> <span style="color: #666666; font-style: italic;"># Sauvegarde de la configuration</span>
<span style="color: #007800;">f_log</span>=<span style="color: #ff0000;">&quot;/var/log/restart_ssh&quot;</span>         <span style="color: #666666; font-style: italic;"># Fichier de log</span>
&nbsp;
<span style="color: #007800;">now</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">$(date +%d/%m/%Y' - '%H:%M)</span>&quot;</span>    <span style="color: #666666; font-style: italic;"># Date et heure pour le log</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> ax <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$f_exe</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
<span style="color: #000000; font-weight: bold;">then</span>
        <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$n_service</span> start <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
        <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> ax <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$f_exe</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
        <span style="color: #000000; font-weight: bold;">then</span>
                <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$now</span>] <span style="color: #007800;">$n_service</span> redémarré automatiquement&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$f_log</span>
        <span style="color: #000000; font-weight: bold;">else</span>
                <span style="color: #c20cb9; font-weight: bold;">rm</span> <span style="color: #007800;">$f_origine</span>
                <span style="color: #c20cb9; font-weight: bold;">cp</span> <span style="color: #007800;">$f_secours</span> <span style="color: #007800;">$f_origine</span>
                <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span><span style="color: #007800;">$n_service</span> start <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
                <span style="color: #000000; font-weight: bold;">if</span> <span style="color: #c20cb9; font-weight: bold;">ps</span> ax <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #007800;">$f_exe</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #660033;">-v</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> <span style="color: #000000; font-weight: bold;">&amp;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
                <span style="color: #000000; font-weight: bold;">then</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$now</span>] <span style="color: #007800;">$n_service</span> redémarré après restauration&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$f_log</span>
                <span style="color: #000000; font-weight: bold;">else</span>
                        <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;[<span style="color: #007800;">$now</span>] <span style="color: #007800;">$n_service</span> arrêté, restauration inefficace&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #007800;">$f_log</span>
                <span style="color: #000000; font-weight: bold;">fi</span>
        <span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #000000; font-weight: bold;">fi</span></pre></div></div>
<p>Crontab root (à adapter selon vos souhaits, ici un lancement du script toutes les minutes) :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">#       minute (de 0 à 59)
&nbsp;
#       |       heure (de 0 à 23)
&nbsp;
#       |       |       jour (de 1 à 31)
&nbsp;
#       |       |       |       mois (de 1 à 12)
&nbsp;
#       |       |       |       |       jour de la semaine (de 0 à 6, 0 = dimanche)
&nbsp;
#       |       |       |       |       |       commande
&nbsp;
        */1     *       *       *       *       /bin/bash /var/scripts/restart_ssh.sh</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/09/21/script-de-relance-automatique-du-serveur-ssh/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Fonction ASP de recherche d&#8217;un utilisateur Active Directory</title>
		<link>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/#comments</comments>
		<pubDate>Sat, 24 Jul 2010 09:00:06 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[ASP]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[active]]></category>
		<category><![CDATA[ad]]></category>
		<category><![CDATA[annuaire]]></category>
		<category><![CDATA[attribut]]></category>
		<category><![CDATA[dc]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[fonction]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[ou]]></category>
		<category><![CDATA[recherche]]></category>
		<category><![CDATA[recordset]]></category>
		<category><![CDATA[subtree]]></category>
		<category><![CDATA[utilisateur]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=1161</guid>
		<description><![CDATA[&#60;% Function RechercheUtilisateur&#40;utilisateur, attribut&#41; &#160; 'Déclaration des variables Dim objConn, objRS Dim Base, Filtre, Scope, Cmd Dim ServeurAD, CompteAD, PwdAD, OU, DC, AttributFiltre &#160; 'Paramétrage ServeurAD = &#34;127.0.0.1&#34; 'Machine hébergeant Active Directory CompteAD = &#34;DOMAINE\admin.ad&#34; 'Utilisateur autorisé à interroger Active Directory PwdAD = &#34;********&#34; 'Mot de passe de cet utilisateur OU = &#34;OU=Utilisateurs&#34; 'OU à [...]]]></description>
			<content:encoded><![CDATA[
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #0000ff; font-weight: bold;">Function</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span>utilisateur, attribut<span style="color: #006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color: #008000;">'Déclaration des variables</span>
<span style="color: #990099; font-weight: bold;">Dim</span> objConn, objRS
<span style="color: #990099; font-weight: bold;">Dim</span> Base, Filtre, Scope, Cmd
<span style="color: #990099; font-weight: bold;">Dim</span> ServeurAD, CompteAD, PwdAD, OU, DC, AttributFiltre
&nbsp;
<span style="color: #008000;">'Paramétrage</span>
ServeurAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;127.0.0.1&quot;</span>           <span style="color: #008000;">'Machine hébergeant Active Directory</span>
CompteAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;DOMAINE\admin.ad&quot;</span>     <span style="color: #008000;">'Utilisateur autorisé à interroger Active Directory</span>
PwdAD <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;********&quot;</span>                <span style="color: #008000;">'Mot de passe de cet utilisateur</span>
OU <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;OU=Utilisateurs&quot;</span>            <span style="color: #008000;">'OU à interroger</span>
DC <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;DC=domaine,DC=fr&quot;</span>           <span style="color: #008000;">'DC à interroger</span>
AttributFiltre <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;sAMAccountName&quot;</span> <span style="color: #008000;">'Filtre de recherche de l'utilisateur</span>
&nbsp;
<span style="color: #008000;">'Connexion à l'annuaire Active Directory</span>
<span style="color: #990099; font-weight: bold;">Set</span> objConn <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;ADODB.Connection&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
objConn.<span style="color: #9900cc;">Provider</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;ADsDSOObject&quot;</span>
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;User ID&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> CompteAD
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Password&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> PwdAD
objConn.<span style="color: #330066;">Properties</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Encrypt Password&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
objConn.<span style="color: #330066;">Open</span>
&nbsp;
<span style="color: #008000;">'Création de la requête</span>
<span style="color: #990099; font-weight: bold;">if</span> attribut<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;&quot;</span> <span style="color: #990099; font-weight: bold;">then</span>
        <span style="color: #008000;">'Permet la recherche simple de l'utilisateur (sans recherche d'attribut)</span>
	attribut <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;sAMAccountName&quot;</span>
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
Base <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;&lt;LDAP://&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> ServeurAD <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;/&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> OU <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;,&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> DC <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;&gt;&quot;</span>
Filtre <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;(&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> AttributFiltre <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;=&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> utilisateur <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;)&quot;</span>
Scope <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;subtree&quot;</span>
Cmd <span style="color: #006600; font-weight: bold;">=</span> Base <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> Filtre <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> attribut <span style="color: #006600; font-weight: bold;">&amp;</span> <span style="color: #cc0000;">&quot;;&quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> Scope
<span style="color: #990099; font-weight: bold;">set</span> objRS <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #990099; font-weight: bold;">Server</span>.<span style="color: #330066;">CreateObject</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;ADODB.Recordset&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #990099; font-weight: bold;">set</span> objRS <span style="color: #006600; font-weight: bold;">=</span> objConn.<span style="color: #330066;">Execute</span><span style="color: #006600; font-weight:bold;">&#40;</span>Cmd<span style="color: #006600; font-weight:bold;">&#41;</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">If</span> objRS.<span style="color: #9900cc;">RecordCount</span> <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #800000;">0</span> <span style="color: #990099; font-weight: bold;">Then</span>
        <span style="color: #008000;">'Aucun utilisateur trouvé</span>
	RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">false</span>
<span style="color: #990099; font-weight: bold;">Else</span>
	<span style="color: #990099; font-weight: bold;">if</span> IsNull<span style="color: #006600; font-weight:bold;">&#40;</span>objRS<span style="color: #006600; font-weight:bold;">&#40;</span>attribut<span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #990099; font-weight: bold;">then</span>
		<span style="color: #008000;">'Utilisateur trouvé, attribut recherché vide</span>
		RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;NULL&quot;</span>
	<span style="color: #990099; font-weight: bold;">else</span>
		<span style="color: #990099; font-weight: bold;">if</span> attribut<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;sAMAccountName&quot;</span> <span style="color: #990099; font-weight: bold;">then</span>
			<span style="color: #008000;">'Utilisateur trouvé, pas d'attribut recherché</span>
			RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #0000ff; font-weight: bold;">true</span>
		<span style="color: #990099; font-weight: bold;">else</span>
			<span style="color: #008000;">'Utilisateur trouvé, attribut recherché non-nul</span>
			RechercheUtilisateur <span style="color: #006600; font-weight: bold;">=</span> objRS<span style="color: #006600; font-weight:bold;">&#40;</span>attribut<span style="color: #006600; font-weight:bold;">&#41;</span>
		<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
	<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #990099; font-weight: bold;">If</span>
&nbsp;
<span style="color: #008000;">'Fermeture du recordset et de la connexion</span>
objRS.<span style="color: #330066;">Close</span>
objConn.<span style="color: #330066;">Close</span>
&nbsp;
<span style="color: #990099; font-weight: bold;">End</span> <span style="color: #0000ff; font-weight: bold;">Function</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Exemple de recherche avec un attribut en paramètre :</p>
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;E-mail : &quot;</span> <span style="color: #006600; font-weight: bold;">&amp;</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;utilisateur.alpha&quot;</span>, <span style="color: #cc0000;">&quot;mail&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Résultat :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">E-mail : utilisateur.alpha@domaine.fr</pre></div></div>
<p>Exemple de recherche &laquo;&nbsp;simple&nbsp;&raquo; :</p>
<div class="wp_syntax"><div class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;%</span>
<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;Utilisateur existant : &quot;</span>
<span style="color: #990099; font-weight: bold;">if</span> RechercheUtilisateur<span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;utilisateur.alpha&quot;</span>,<span style="color: #cc0000;">&quot;&quot;</span><span style="color: #006600; font-weight:bold;">&#41;</span><span style="color: #006600; font-weight: bold;">=</span><span style="color: #0000ff; font-weight: bold;">true</span> <span style="color: #990099; font-weight: bold;">then</span>
	<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;oui&quot;</span>
<span style="color: #990099; font-weight: bold;">else</span>
	<span style="color: #990099; font-weight: bold;">Response</span>.<span style="color: #330066;">Write</span> <span style="color: #cc0000;">&quot;non&quot;</span>
<span style="color: #990099; font-weight: bold;">end</span> <span style="color: #990099; font-weight: bold;">if</span>
<span style="color: #000000; font-weight: bold;">%&gt;</span></pre></div></div>
<p>Résultat :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Utilisateur existant : oui</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/07/24/fonction-asp-de-recherche-dun-utilisateur-active-directory/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Modifier le message &#171;&#160;Appuyez sur une touche pour continuer&#8230;&#160;&#187;</title>
		<link>http://blog.nicolas.pawlak.fr/2010/03/29/modifier-le-message-appuyez-sur-une-touche-pour-continuer/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/03/29/modifier-le-message-appuyez-sur-une-touche-pour-continuer/#comments</comments>
		<pubDate>Mon, 29 Mar 2010 21:00:15 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Batch]]></category>
		<category><![CDATA[bat]]></category>
		<category><![CDATA[com]]></category>
		<category><![CDATA[pause]]></category>
		<category><![CDATA[powerbatch]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=773</guid>
		<description><![CDATA[En batch, la commande pause affiche le message suivant dans le script : Appuyez sur une touche pour continuer... Il est possible de personnaliser ce message, tout en conservant sa fonction d&#8217;arrêt temporaire du déroulement du script, par ce moyen : @echo off echo Appuyez sur la touche de votre choix pour poursuivre... pause&#62;nul exit [...]]]></description>
			<content:encoded><![CDATA[<p>En <a href="http://scudo.free.fr/Faq/dos/batches.htm">batch</a>, la commande <em><a href="http://1100f.free.fr/Batchs/la_commande_pause.htm">pause</a></em> affiche le message suivant dans le script :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Appuyez sur une touche pour continuer...</pre></div></div>
<p>Il est possible de personnaliser ce message, tout en conservant sa fonction d&#8217;arrêt temporaire du déroulement du script, par ce moyen :</p>
<div class="wp_syntax"><div class="code"><pre class="winbatch" style="font-family:monospace;"><span style="color: #66cc66;">@</span>echo <span style="color: #0080FF; font-weight: bold;">off</span>
echo Appuyez sur la touche de votre choix pour poursuivre...
pause<span style="color: #66cc66;">&gt;</span>nul
<span style="color: #800080;">exit</span></pre></div></div>
<p>Cette personnalisation n&#8217;a pas qu&#8217;un but esthétique, elle peut-être nécessaire dans plusieurs cas :</p>
<p><strong>Utilisation de PowerBatch</strong></p>
<p><a href="http://www.laboratoire-microsoft.org/logiciels/11839/">PowerBatch</a> est un outil permettant entre autres de <a href="http://fr.wikipedia.org/wiki/Compilateur">compiler</a> des fichiers .bat pour les transformer en applications <a href="http://fr.wikipedia.org/wiki/DOS">DOS</a>/Windows. C&#8217;est un outil très intéressant, cependant le résultat de la commande pause s&#8217;affiche dans la langue de Shakespeare&#8230; </p>
<p>Ceci dit, il était peut-être préférable d&#8217;éviter le français à chaque message, si ça pouvait aider à éviter ce genre d&#8217;horreur orthographique :</p>
<p align="center"'><a href="http://blog.nicolas.pawlak.fr/wp-content/uploads/2010/03/powerbatch.png"><img src="http://blog.nicolas.pawlak.fr/wp-content/uploads/2010/03/powerbatch.png" alt="" title="powerbatch" width="381" height="304" class="aligncenter size-full wp-image-790" /></a></p>
<p>Dans le cas où vous souhaiteriez créer un fichier .com à partir de votre fichier .bat, il semble donc préférable de contrôler réellement les messages d&#8217;information pouvant être affichés et les personnaliser si besoin.</p>
<p><strong>Exécution sur un environnement en langue étrangère</strong></p>
<p>Quoi, vous pensiez que sur un système en anglais, vous auriez un beau message de pause en français ? Il ne faut pas rêver&#8230; Cette méthode vous permet donc d&#8217;éviter l&#8217;aberration suivante :</p>
<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">Mon système est en anglais.
Mon script est en français.
&nbsp;
Press any key to continue...</pre></div></div>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/03/29/modifier-le-message-appuyez-sur-une-touche-pour-continuer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Connaître son IP publique en bash</title>
		<link>http://blog.nicolas.pawlak.fr/2010/03/26/connaitre-son-ip-publique-en-bash/</link>
		<comments>http://blog.nicolas.pawlak.fr/2010/03/26/connaitre-son-ip-publique-en-bash/#comments</comments>
		<pubDate>Fri, 26 Mar 2010 19:00:17 +0000</pubDate>
		<dc:creator>Nicolas</dc:creator>
				<category><![CDATA[Shell]]></category>
		<category><![CDATA[checkip]]></category>
		<category><![CDATA[dynamique]]></category>
		<category><![CDATA[dyndns]]></category>
		<category><![CDATA[ip]]></category>
		<category><![CDATA[publique]]></category>
		<guid isPermaLink="false">http://blog.nicolas.pawlak.fr/?p=758</guid>
		<description><![CDATA[Un petit script tout simple, mais qui peut rendre bien des services. #!/bin/bash wget http://checkip.dyndns.org/ -O - -o /dev/null &#124; awk '{ print $6 }' &#124; cut -d &#34;&#60;&#34; -f 1 DynDNS est un service permettant notamment de disposer d&#8217;un domaine pointant toujours vers votre adresse IP, même si cette dernière est dynamique.]]></description>
			<content:encoded><![CDATA[<p>Un petit script tout simple, mais qui peut rendre bien des services.</p>
<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/bash</span>
<span style="color: #c20cb9; font-weight: bold;">wget</span> http:<span style="color: #000000; font-weight: bold;">//</span>checkip.dyndns.org<span style="color: #000000; font-weight: bold;">/</span> <span style="color: #660033;">-O</span> - <span style="color: #660033;">-o</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print  $6 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">cut</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">&quot;&lt;&quot;</span> <span style="color: #660033;">-f</span> <span style="color: #000000;">1</span></pre></div></div>
<p><em><a href="http://www.dyndns.com/">DynDNS</a> est un service permettant notamment de disposer d&#8217;un domaine pointant toujours vers votre <a href="http://fr.wikipedia.org/wiki/Adresse_IP">adresse IP</a>, même si cette dernière est <a href="http://www.dictionnaire.referencement-1ere-page.com/A/Adresse-IP-dynamique">dynamique</a>.</em></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.nicolas.pawlak.fr/2010/03/26/connaitre-son-ip-publique-en-bash/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

