<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" xml:lang="en">
  <title>Keyphrene's Blog</title>
  <link rel="alternate" type="text/html" href="http://blog.keyphrene.com/keyphrene/index.php/" />
  
  <subtitle type="text">keyphrene's news, Tutorial org.keyphrene, Naja</subtitle>
  <id>tag:blog.keyphrene.com,2012:/keyphrene/index.php/</id>

  <updated>2010-12-30T07:42:52+01:00</updated>
  <generator version="1.2.8" uri="http://www.dotclear.net/">DotClear</generator>

  <sy:updatePeriod>daily</sy:updatePeriod>
  <sy:updateFrequency>1</sy:updateFrequency>
  <sy:updateBase>2010-12-30T07:42:52+01:00</sy:updateBase>

<atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" type="application/atom+xml" href="http://feeds.feedburner.com/KeyphreneBlog" /><feedburner:info uri="keyphreneblog" /><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com/" /><entry xml:lang="en">
  <title>Introduction to the Windows Shell</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/7xL4OxWo0k4/24-introduction-to-the-windows-shell" />
  <updated>2010-12-30T07:42:52+01:00</updated>
  <id>tag:blog.keyphrene.com,2010-12-30:/keyphrene/24</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-windows" label="Shell Windows" />
  <summary>Introduction to the Windows Shell (DOS)</summary>
  <content type="html">&lt;p&gt;Introduction to the Windows Shell (DOS)&lt;/p&gt; &lt;h2&gt;Condition&lt;/h2&gt;

&lt;pre&gt;[dos]
IF NOT ERRORLEVEL 1 echo OK
&lt;/pre&gt;


&lt;h2&gt;Concatenation&lt;/h2&gt;

&lt;pre&gt;[dos]
SETLOCAL ENABLEDELAYEDEXPANSION 
SET CLASSPATH=
FOR %%I IN (*.jar) DO (
SET CLASSPATH=!CLASSPATH!%%~fI;
)
&lt;/pre&gt;


&lt;h2&gt;Replace&lt;/h2&gt;

&lt;pre&gt;[dos]
set TEST=c:\Windows\tmp
set TEST2=%TEST:\=/%
echo %TEST2%
REM c:/Windows/tmp
&lt;/pre&gt;


&lt;h2&gt;Loop&lt;/h2&gt;

&lt;pre&gt;[dos]
REM Simple loop (1 to 5)
FOR /L %%I IN (1,1,5) DO (
	echo %%I
)

REM filename list without path
FOR %%I IN (*.txt) DO (
    echo %%~nxI
)

REM filename list with path
FOR %%I IN (*.txt) DO (
    echo %%~fI
)

REM Directory list (recursive)
FOR /R C:\ %%I IN (*) DO (
    echo %%~pI
)

REM filename pattern list (recursive)
FOR /R C:\ %%I IN (*.txt) DO (
    echo %%I
)
&lt;/pre&gt;


&lt;h2&gt;Output redirection&lt;/h2&gt;

&lt;pre&gt;[dos]
# Standard output
filename.exe &amp;gt; NUL

# Standard output and Error output
filename.exe &amp;gt; NUL 2&amp;amp;&amp;gt;1
&lt;/pre&gt;


&lt;h2&gt;FAQs&lt;/h2&gt;


&lt;h3&gt;Variables&lt;/h3&gt;

&lt;pre&gt;[dos]
REM Display the current directory
echo %CD%
REM data time
echo %DATE% %TIME%
REM random 	between 0 and 32767
echo %RANDOM%
&lt;/pre&gt;


&lt;h3&gt;How put a date in variable&lt;/h3&gt;

&lt;pre&gt;[dos]
FOR /F &amp;quot;tokens=1-3 delims=/ &amp;quot; %%i IN ('DATE /T') DO (
	SET DATUM=%%k-%%j-%%i
)
&lt;/pre&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/12/30/24-introduction-to-the-windows-shell</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>How to create a thumbnail from a video with a DOS script and ffmpeg</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/DU6jzCqvT6E/31-how-to-create-a-thumbnail-from-a-video-with-a-dos-script-and-ffmpeg" />
  <updated>2010-12-30T07:39:34+01:00</updated>
  <id>tag:blog.keyphrene.com,2010-12-30:/keyphrene/31</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-windows" label="Shell Windows" />
  <summary>How to create a thumbnail from a video with a DOS script and FFMPEG</summary>
  <content type="html">&lt;p&gt;How to create a thumbnail from a video with a DOS script and FFMPEG&lt;/p&gt; &lt;ul&gt;
&lt;li&gt;Dowload FFMPEG for Windows &lt;a href="http://www.keyphrene.com/download/ffmpeg.zip" hreflang="en"&gt;ffmpeg.zip&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Create Thumbnails _movies.bat on your desktop.&lt;/li&gt;
&lt;li&gt;Define ffmpeg.exe into FFMPEG variable.&lt;/li&gt;
&lt;li&gt;Drag and drop a directory or file movie above your script.&lt;/li&gt;
&lt;li&gt;This script is recursive for your directory&lt;/li&gt;
&lt;/ul&gt;

&lt;pre&gt;[dos]
@echo off
 
set FFMPEG=D:\share\ffmpeg.exe
set PATHIN=%1
set RNDSTART=100 
set RNDEND=200
 
SETLOCAL enabledelayedexpansion
call:IsDir %PATHIN%
IF %ERRORLEVEL% == 0 (
    REM This is a directory
	FOR /R %PATHIN% %%I IN (*.avi *.mkv) DO ( 
		echo &amp;quot;%%~dpI&amp;quot;
		IF NOT EXIST &amp;quot;%%~dpnI.jpeg&amp;quot; (
		echo &amp;quot;%%~dpnI.jpeg&amp;quot;
		call:Randomize rnd &amp;quot;%RNDSTART%&amp;quot; &amp;quot;%RNDEND%&amp;quot;
		%FFMPEG% -itsoffset -!rnd! -y -i &amp;quot;%%~fI&amp;quot; -vcodec mjpeg -vframes 1 -an -f rawvideo -s 128x128 &amp;quot;%%~dpnI.jpeg&amp;quot; &amp;gt; NUL 2&amp;gt;&amp;amp;1 
		)
	)
) ELSE (
    REM This is a file
	call:FilenameFormat ret %PATHIN% dpn;
	IF NOT EXIST &amp;quot;!ret!.jpeg&amp;quot; (
	echo &amp;quot;!ret!.jpeg&amp;quot;
	call:Randomize rnd &amp;quot;%RNDSTART%&amp;quot; &amp;quot;%RNDEND%&amp;quot;;
	REM echo %FFMPEG% -itsoffset -!rnd! -y -i %PATHIN% -vcodec mjpeg -vframes 1 -an -f rawvideo -s 128x128 &amp;quot;!ret!.jpeg&amp;quot;
	%FFMPEG% -itsoffset -!rnd! -y -i %PATHIN% -vcodec mjpeg -vframes 1 -an -f rawvideo -s 128x128 &amp;quot;!ret!.jpeg&amp;quot; &amp;gt; NUL 2&amp;gt;&amp;amp;1 
	)
)
 
pause
 
REM ===================
REM = Functions
REM ===================
 
 
:FilenameFormat
SETLOCAL
IF &amp;quot;%~1&amp;quot;==&amp;quot;&amp;quot; GOTO:EOF
FOR %%i IN (&amp;quot;%~2&amp;quot;) DO SET r=%%~%~3i
( ENDLOCAL
    SET &amp;quot;%~1=%r%&amp;quot;
)
GOTO:EOF
 
:IsDir
FOR /F &amp;quot;delims=&amp;quot; %%i IN (&amp;quot;%~1&amp;quot;) DO SET MYPATH=&amp;quot;%%~fi&amp;quot;
PUSHD %MYPATH% 2&amp;gt;NUL
IF ERRORLEVEL 0 (
    POPD
)
GOTO:EOF
 
:Randomize
SETLOCAL
IF &amp;quot;%~2&amp;quot;==&amp;quot;&amp;quot; GOTO:EOF
SET /a &amp;quot;r=%RANDOM% %% %~3 + %~2&amp;quot; &amp;gt; NUL
( ENDLOCAL
    set &amp;quot;%~1=%r%&amp;quot;
)
GOTO:EOF

&lt;/pre&gt;


&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : FFMPEG thumbnail movie script DOS&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/12/30/31-how-to-create-a-thumbnail-from-a-video-with-a-dos-script-and-ffmpeg</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>Time Left Format Shell function</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/vdvrX759Aag/35-time-left-format-shell-function" />
  <updated>2010-07-15T06:50:30+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-07-15:/keyphrene/35</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-unix" label="Shell Unix" />
  <summary>Time Left Format Shell function (Tutorial Shell function)</summary>
  <content type="html">&lt;p&gt;Time Left Format Shell function (Tutorial Shell function)&lt;/p&gt; &lt;pre&gt;[bash]

TimeLeftFormat()
{
	# format = d for day, default is hour
	sec=$1
	format=$2
	if [ $format&amp;quot;&amp;quot; = &amp;quot;d&amp;quot; ]; then
		echo $(($sec/86400))d `TimeLeftFormat $(($sec%86400))`
	else
		echo $(($sec/3600))h $((($sec%3600)/60))m $((($sec%3600)%60))s
	fi
}

time_left=`TimeLeftFormat 10000`
echo $time_left
# 2h 46m 40s

time_left=`TimeLeftFormat 100000 d`
echo $time_left
# 1d 3h 46m 40s

# Get timestamp with date '+%s' 
TIME_START=`date '+%s'`
TIME_END=`date '+%s'`

# Make difference
time_left=$((TIME_END - TIME_START))
time_left=`TimeLeftFormat $time_left`
echo $time_left

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt;: Tutorial Shell function time date format&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/07/15/35-time-left-format-shell-function</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>Filename Format DOS function</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/Wcn52tNCSak/34-filename-format-dos-function" />
  <updated>2010-07-15T06:50:29+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-07-15:/keyphrene/34</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-windows" label="Shell Windows" />
  <summary>Get filename with different format. Split filename (Tutorial DOS function)</summary>
  <content type="html">&lt;p&gt;Get filename with different format. Split filename (Tutorial DOS function)&lt;/p&gt; &lt;p&gt;Get filename with different format&lt;/p&gt;


&lt;p&gt;Examples:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;dpn: D:\path\to\name\filename&lt;/li&gt;
&lt;li&gt;pn: \path\to\name\filename&lt;/li&gt;
&lt;li&gt;n: \path\to\name&lt;/li&gt;
&lt;li&gt;n: filename&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;[dos]
SETLOCAL enabledelayedexpansion
SET MYFILENAME=&amp;quot;D:\path\to\name\filename.ext&amp;quot;
call:FilenameFormat ret %MYFILENAME% dpn
ECHO !ret!
REM Result D:\path\to\name\filename

:FilenameFormat
SETLOCAL
IF &amp;quot;%~1&amp;quot;==&amp;quot;&amp;quot; GOTO:EOF
FOR %%i IN (&amp;quot;%~2&amp;quot;) DO SET r=%%~%~3i
( ENDLOCAL
    SET &amp;quot;%~1=%r%&amp;quot;
)
GOTO:EOF

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Tutorial DOS function filename format split SET SETLOCAL enabledelayedexpansion&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/07/15/34-filename-format-dos-function</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>IsDir DOS function</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/QAKc3RZIM6o/33-isdir-dos-function" />
  <updated>2010-07-15T06:47:41+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-07-15:/keyphrene/33</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-windows" label="Shell Windows" />
  <summary>Detect if your pathname is a directory. (Tutorial DOS function)</summary>
  <content type="html">&lt;p&gt;Detect if your pathname is a directory. (Tutorial DOS function)&lt;/p&gt; &lt;p&gt;Detect if your pathname is a directory&lt;/p&gt;

&lt;pre&gt;[dos]

set A=&amp;quot;D:\path\to\name&amp;quot;

call:IsDir %A%
IF %ERRORLEVEL% == 0 (
    echo &amp;quot;Directory found&amp;quot;
) ELSE (
    echo &amp;quot;Directory not found&amp;quot;
)

:IsDir
FOR /F &amp;quot;delims=&amp;quot; %%i IN (&amp;quot;%~1&amp;quot;) DO SET MYPATH=&amp;quot;%%~fi&amp;quot;
PUSHD %MYPATH% 2&amp;gt;NUL
IF ERRORLEVEL 0 (
    POPD
)
GOTO:EOF

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Tutorial DOS function Is Directory IsDir ERRORLEVEL FOR PUSHD POPD&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/07/15/33-isdir-dos-function</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>Randomize DOS function</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/QK0qgWNV24g/32-randomize-dos-function" />
  <updated>2010-07-15T06:44:01+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-07-15:/keyphrene/32</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-windows" label="Shell Windows" />
  <summary>Randomize DOS function. (Tutorial DOS function)</summary>
  <content type="html">&lt;p&gt;Randomize DOS function. (Tutorial DOS function)&lt;/p&gt; &lt;pre&gt;[dos]

SETLOCAL enabledelayedexpansion
call:Randomize rnd 100 200
echo !rnd!

:Randomize
SETLOCAL enabledelayedexpansion
IF &amp;quot;%~2&amp;quot;==&amp;quot;&amp;quot; GOTO:EOF
SET /a &amp;quot;r=%RANDOM% %% %~3 + %~2&amp;quot; &amp;gt; NUL
( ENDLOCAL
    set &amp;quot;%~1=%r%&amp;quot;
)
GOTO:EOF

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Tutorial DOS function Randomize SETLOCAL SET enabledelayedexpansion&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/07/15/32-randomize-dos-function</feedburner:origLink></entry>
<entry xml:lang="fr">
  <title>Wake On Lan chez Free</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/O5z7EsF7Z7A/30-wake-on-lan-chez-free" />
  <updated>2010-06-25T07:11:27+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-06-25:/keyphrene/30</id>
  <author><name>keyphrene</name></author>
  <category term="Freebox" label="Freebox" />
  <summary>Wake On Lan chez Free, réveiller votre ordinateur depuis internet.</summary>
  <content type="html">&lt;p&gt;Wake On Lan chez Free, réveiller votre ordinateur depuis internet.&lt;/p&gt; &lt;h5&gt;Configurer votre BIOS&lt;/h5&gt;


&lt;p&gt;Aller dans votre BIOS pour activer la Wake On Lan&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;Exemple: Sur ma carte ASUS PK5 SE, la mention wake on lan n'y figure pas
Je dois me rendre dans le menu "Power", "APM" et activer les fonctions&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;WakeUp PCI&lt;/li&gt;
&lt;li&gt;WakeUp PCI-E&lt;/li&gt;
&lt;/ul&gt;

&lt;h5&gt;Configurer votre driver de carte réseau&lt;/h5&gt;


&lt;p&gt;Aller dans le gestionnaire de périphériques&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;Ouvrer les propriétés de votre carte réseau&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src="http://www.keyphrene.com/img/peripheriques.png" alt="" /&gt;&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;Mettre à "On" l'option "Shutdown Wake Up"&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src="http://www.keyphrene.com/img/wakeonlan1.png" alt="" /&gt;&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;Mettre à "Magic Packet" l'option "Wake Up Capabilities"&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src="http://www.keyphrene.com/img/wakeonlan2.png" alt="" /&gt;&lt;/p&gt;


&lt;h5&gt;Configurer votre Freebox&lt;/h5&gt;


&lt;p&gt;Activer la fonction Proxy Wol (Wake On Lan)&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;&lt;img src="http://www.keyphrene.com/img/freewakeonlan.png" alt="" /&gt;&lt;br /&gt;&lt;/p&gt;


&lt;p&gt;Le redémarrage de votre Freebox est nécessaire pour activer la configuration&lt;/p&gt;


&lt;h5&gt;Récupérer l'adresse Mac de votre carte réseau&lt;/h5&gt;


&lt;p&gt;Ouvrer une command dos (cmd.exe) et la lancer la commande suivante&lt;br /&gt;&lt;/p&gt;


&lt;pre&gt;ipconfig /all&lt;/pre&gt;

&lt;p&gt;Vous obtenez l'adresse suivante&lt;/p&gt;

&lt;pre&gt;Adresse physique . . . . . . . . .: 00-12-4c-d5-78-dc&lt;/pre&gt;


&lt;p&gt;Sous windows Vista et Seven, vous devez démarrer la cmd.exe en tant qu'administrateur&lt;/p&gt;


&lt;h5&gt;Installer votre script wakeonlan.php chez un hébergeur&lt;/h5&gt;

&lt;pre&gt;[php]
&amp;lt;?
# Wake on LAN - (c) HotKey@spr.at, upgraded by Murzik
# Modified by Allan Barizo http://www.hackernotcracker.com
flush();
function WakeOnLan($addr, $mac,$socket_number) {
  $addr_byte = explode(':', $mac);
  $hw_addr = '';
  for ($a=0; $a &amp;lt;6; $a++) $hw_addr .= chr(hexdec($addr_byte[$a]));
  $msg = chr(255).chr(255).chr(255).chr(255).chr(255).chr(255);
  for ($a = 1; $a &amp;lt;= 16; $a++) $msg .= $hw_addr;
  // send it to the broadcast address using UDP
  // SQL_BROADCAST option isn't help!!
  $s = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
  if ($s == false) {
	echo &amp;quot;Error creating socket!\n&amp;quot;;
	echo &amp;quot;Error code is '&amp;quot;.socket_last_error($s).&amp;quot;' - &amp;quot; . socket_strerror(socket_last_error($s));
	return FALSE;
	}
  else {
	// setting a broadcast option to socket:
	$opt_ret = socket_set_option($s, 1, 6, TRUE);
	if($opt_ret &amp;lt;0) {
	  echo &amp;quot;setsockopt() failed, error: &amp;quot; . strerror($opt_ret) . &amp;quot;\n&amp;quot;;
	  return FALSE;
	  }
	if(socket_sendto($s, $msg, strlen($msg), 0, $addr, $socket_number)) {
	  echo &amp;quot;Magic Packet sent successfully!&amp;quot;;
	  socket_close($s);
	  return TRUE;
	  }
	else {
	  echo &amp;quot;Magic packet failed!&amp;quot;;
	  return FALSE;
	  }
	}
  }
// Port number where the computer is listening. Usually, any number between 1-50000 will do. Normally people choose 7 or 9.
$socket_number = &amp;quot;9&amp;quot;;

// MAC Address of the listening computer's network device 00:1b:fc:c3:0c:3d
$mac_addy = &amp;quot;00:12:4c:d5:78:dc&amp;quot;;
// IP address of the listening computer. Input the domain name if you are using a hostname (like when under Dynamic DNS/IP)
$ip_addy = &amp;quot;10.10.10.1&amp;quot;;
WakeOnLan($ip_addy, $mac_addy,$socket_number)
?&amp;gt;
&lt;/pre&gt;


&lt;p&gt;Remplacer $mac_addy="votre adresse mac" et $ip_addy="votre adresse publique"
Attention, l'adresse MAC doit avoir comme séparateur ":" et être en minuscule pour les lettres&lt;/p&gt;


&lt;h5&gt;Tester le démarrage de votre serveur&lt;/h5&gt;


&lt;p&gt;Lancer votre script
http://&amp;lt;votre_domaine&amp;gt;/wakeonlan.php&lt;/p&gt;


&lt;p&gt;ou vous pouvez utiliser ce service&lt;/p&gt;
&lt;a href="http://www.keyphrene.com/services/wakeonlan/" target="_blank"&gt;WakeOnLan&lt;/a&gt;




&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt;&amp;nbsp;: Wake on lan Free Freebox script PHP magic packet BIOS wake up&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/06/25/30-wake-on-lan-chez-free</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>How to archive the most recent directories</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/5uyV7cXQ7Fc/29-how-to-archive-the-most-recent-directories" />
  <updated>2010-06-10T11:47:24+02:00</updated>
  <id>tag:blog.keyphrene.com,2010-06-10:/keyphrene/29</id>
  <author><name>keyphrene</name></author>
  <category term="Tutorialorgkeyphrene" label="Org.keyphrene - 4Py" />
  <summary>How to archive the most recent directories. (Tutorial Shell Unix)</summary>
  <content type="html">&lt;p&gt;How to archive the most recent directories. (Tutorial Shell Unix)&lt;/p&gt; &lt;pre&gt;[bash]

archive_directory()
{
	local n=0
	local arch=5
	local arch_path=&amp;quot;&amp;quot;
	
	if [ -d &amp;quot;$1&amp;quot; ]; then
		arch_path=$1
	else
		echo archive_directory: $1 not found
		return
	fi
	if [ -n &amp;quot;$2&amp;quot; ]; then
		arch=$2
	fi
	
	echo $arch_path $arch
	
	d=ARCH_`date +%Y%m%d`
	mkdir -p $d
	
	find $arch_path -type f -mindepth 1 -maxdepth 1 | while read i
	do
		mv &amp;quot;$i&amp;quot; &amp;quot;$arch_path/$d/&amp;quot;
	done
	
	# Remove ARCH_
	find $arch_path -type d -mindepth 1 -maxdepth 1 | sort -r | while read i
	do
		n=$(($n+1))
		if [ $n -le $arch ]; then
			echo &amp;quot;Keep $i&amp;quot;
			continue
		fi
		echo &amp;quot;Delete $i&amp;quot;
		rm -fr &amp;quot;$i&amp;quot;
	done
}

# Archiving the five last directories
archive_directory D:/temp/tmp

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Tutorial Shell Unix archive recent directory forlder Script DOS&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/06/10/29-how-to-archive-the-most-recent-directories</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>How to archive the most recent files</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/pWDOaju2i5s/28-how-to-archive-the-most-recent-files" />
  <updated>2010-02-20T11:36:02+01:00</updated>
  <id>tag:blog.keyphrene.com,2010-02-20:/keyphrene/28</id>
  <author><name>keyphrene</name></author>
  <category term="Shell-unix" label="Shell Unix" />
  <summary>How to archive the most recent files. (Tutorial Shell Unix)</summary>
  <content type="html">&lt;p&gt;How to archive the most recent files. (Tutorial Shell Unix)&lt;/p&gt; &lt;p&gt;This script keep the last five files&lt;/p&gt;

&lt;pre&gt;[bash]
# Archiving /path/to/name/pattern*.tar.gz

n=0
arch=5
for i in `ls -ltr backup.sql*.tar.gz | awk '{print $9}' | sort -r `
do
	n=`expr $n + 1`
	if [ $n -le $arch ]; then
		echo &amp;quot;Keep &amp;quot;$i
		continue
	fi
	echo &amp;quot;Delete &amp;quot;$i
	rm -f $i
done

&lt;/pre&gt;



&lt;p&gt;Another example&lt;/p&gt;
&lt;pre&gt;[bash]
archive_file()
{
	local arch=5
	local arch_pattern=$1
	
	if [ -n &amp;quot;$2&amp;quot; ]; then
		arch=$2
	fi
	
	ls -t $arch_pattern | tail -n +$(($arch+1)) | xargs rm -f 
}

archive_file &amp;quot;/tmp/backup*.sql.tar.gz&amp;quot;
&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Tutorial Shell Unix archive recent files&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/02/20/28-how-to-archive-the-most-recent-files</feedburner:origLink></entry>
<entry xml:lang="en">
  <title>authenticate method in PHP</title>
  <link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/KeyphreneBlog/~3/f9oknMRbKi0/27-authenticate-method-in-php" />
  <updated>2010-01-07T17:37:23+01:00</updated>
  <id>tag:blog.keyphrene.com,2010-01-07:/keyphrene/27</id>
  <author><name>keyphrene</name></author>
  <category term="Webdav_php" label="Webdav server in PHP" />
  <summary>[php]
&lt;?
# Author: Vincent JAULIN

// function to parse the http auth header
function http_digest_parse($txt)
{
    // protect against missing data
    $needed_parts = array('nonce'=&gt;1, 'nc'=&gt;1, 'cnonce'=&gt;1, 'qop'=&gt;1, 'username'=&gt;1, 'uri'=&gt;1, 'response'=&gt;1);...</summary>
  <content type="html"> &lt;pre&gt;[php]
&amp;lt;?
# Author: Vincent JAULIN

// function to parse the http auth header
function http_digest_parse($txt)
{
    // protect against missing data
    $needed_parts = array('nonce'=&amp;gt;1, 'nc'=&amp;gt;1, 'cnonce'=&amp;gt;1, 'qop'=&amp;gt;1, 'username'=&amp;gt;1, 'uri'=&amp;gt;1, 'response'=&amp;gt;1);
    $data = array();

    preg_match_all('@(\w+)=([\'&amp;quot;]?)([%a-zA-Z0-9=./\_-]+)\2@', $txt, $matches, PREG_SET_ORDER);

    foreach ($matches as $m) {
        $data[$m[1]] = $m[3];
        unset($needed_parts[$m[1]]);
    }

    return $needed_parts ? false : $data;
}

function AuthenticationDigestHTTP($realm, $users, $phpcgi=0) {
	if (empty($_SERVER['PHP_AUTH_DIGEST']) &amp;amp;&amp;amp; empty($_SERVER['REDIRECT_REMOTE_USER'])){
		header('HTTP/1.1 401 Unauthorized');
		header('WWW-Authenticate: Digest realm=&amp;quot;'.$realm.'&amp;quot; qop=&amp;quot;auth&amp;quot; nonce=&amp;quot;'.uniqid(rand(), true).'&amp;quot; opaque=&amp;quot;'.md5($realm).'&amp;quot;');
		die('401 Unauthorized');
	}
	// analyze the PHP_AUTH_DIGEST variable
	$auth = $_SERVER['PHP_AUTH_DIGEST'];
	if ($phpcgi == 1) {
		$auth = $_SERVER['REDIRECT_REMOTE_USER'];
	}
	$data = http_digest_parse($auth);
	if (!array_key_exists($data['username'], $users)) {
		header('HTTP/1.1 401 Unauthorized');
		die('401 Unauthorized');
	}
		
	// generate the valid response
	$A1 = md5($data['username'] . ':' . $realm . ':' . $users[$data['username']]);
	$A2 = md5($_SERVER['REQUEST_METHOD'].':'.$data['uri']);
	$valid_response = md5($A1.':'.$data['nonce'].':'.$data['nc'].':'.$data['cnonce'].':'.$data['qop'].':'.$A2);
	
	if ($data['response'] != $valid_response) {
		header('HTTP/1.1 401 Unauthorized');
		die('401 Unauthorized');
	}
	return TRUE;
}

function AuthenticationBasicHTTP($realm, $users, $phpcgi=0) {
	if (empty($_SERVER['PHP_AUTH_USER']) &amp;amp;&amp;amp; empty($_SERVER['REDIRECT_REMOTE_USER'])) {
		header('WWW-Authenticate: Basic realm=&amp;quot;'.$realm.'&amp;quot;');
		header('HTTP/1.0 401 Unauthorized');
		die('401 Unauthorized');
	}
	
	$user = $_SERVER['PHP_AUTH_USER'];
	if ($phpcgi == 1) {		
		$matches = explode(' ', $_SERVER['REDIRECT_REMOTE_USER']);
		list($name, $password) = explode(':', base64_decode($matches[1]));
		$_SERVER['PHP_AUTH_USER'] = $user = strip_tags($name);
		$_SERVER['PHP_AUTH_PW']    = strip_tags($password);
	}

	if (array_key_exists($user, $users) &amp;amp;&amp;amp; $users[$user] == $_SERVER['PHP_AUTH_PW'] ){
		return TRUE;
	}

	header('WWW-Authenticate: Basic realm=&amp;quot;'.$realm.'&amp;quot;');
	header('HTTP/1.0 401 Unauthorized');
	die('401 Unauthorized');
	return FALSE;
}



?&amp;gt;

&lt;/pre&gt;



&lt;p&gt;&lt;strong&gt;TAGS&lt;/strong&gt; : Script PHP authentication Digest Basic for Webdav&lt;/p&gt;</content>
<feedburner:origLink>http://blog.keyphrene.com/keyphrene/index.php/2010/01/07/27-authenticate-method-in-php</feedburner:origLink></entry>
</feed>

