<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
	<channel>
		<atom:link href="http://forum.ubuntu-fr.org/extern.php?action=feed&amp;tid=375951&amp;type=rss" rel="self" type="application/rss+xml" />
		<title><![CDATA[Forum Ubuntu-fr.org / Problème script synchro]]></title>
		<link>http://forum.ubuntu-fr.org/viewtopic.php?id=375951</link>
		<description><![CDATA[Les sujets les plus récents dans Problème script synchro.]]></description>
		<lastBuildDate>Sun, 31 Jan 2010 12:42:25 +0000</lastBuildDate>
		<generator>FluxBB</generator>
		<item>
			<title><![CDATA[Réponse à&#160;:  Problème script synchro]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3249130#p3249130</link>
			<description><![CDATA[<p>Personne ? <img src="http://forum.ubuntu-fr.org/img/smilies/hmm.png" width="15" height="15" alt="hmm" /></p>]]></description>
			<author><![CDATA[dummy@example.com (RastaYoupi)]]></author>
			<pubDate>Sun, 31 Jan 2010 12:42:25 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3249130#p3249130</guid>
		</item>
		<item>
			<title><![CDATA[Problème script synchro]]></title>
			<link>http://forum.ubuntu-fr.org/viewtopic.php?pid=3245662#p3245662</link>
			<description><![CDATA[<p>Salut à tous,<br />J&#039;espère que je me suis pas gouré mais je vois pas où je pourrai mettre mon sujet.<br />Modo soyez indulgent ^^<br />Le topo, j&#039;ai un système live sur une clef usb et je veux synchroniser le home de ma clef avec un répertoire de mon poste fixe.<br />Pour cela j&#039;ai commencé par identifier ma clef de façon unique avec Udev, au passage si quelqu&#039;un sait pourquoi je ne vois plus ma clef en faisant un fdisk -l, je devrai &#039;&quot;normalement&quot; voir /dev/lenomdemaclef.<br />Bref à chaque connexion de la clef une règle Udev appelle u script pour faire une synchro.<br />J&#039;ai un peu pris pas mal de bout de script à droite, à gauche et presque tout marche sauf l&#039;affichage graphique.<br />Du moins je veux juste une barre de progression et un pop up pour dire que la synchro est terminée.<br />Je me suis inspiré du code de &quot;koderez&quot; dans ce topic http://forum.ubuntu-fr.org/viewtopic.php?id=82232&amp;p=12<br />Attention c&#039;est peu être un peu le fouillis, fin si vous comprenez pas certaines choses dite moi :-)</p><p>Le code:</p><div class="codebox"><pre class="vscroll"><code>#! /bin/sh
######################################################################################
# Script de gestion de connexion et sauvegarde du /home de la clef sur le poste fixe #
######################################################################################

afficheTaille () {
  taille=$(sed &#039;/\./! s/^.*$/&amp;.00/&#039; &lt;&lt;&lt; $1)
  i=1
  while [[ ${#taille} -ge 7 ]]; do
    taille=$(bc &lt;&lt;&lt; &quot;scale=2;$taille/1024&quot;)
    ((i+=1))
  done

  case $i in
    1) taille+=&quot; octets&quot; ;;
    2) taille+=&quot; Ko&quot; ;;
    3) taille+=&quot; Mo&quot; ;;
    4) taille+=&quot; Go&quot; ;;
  esac

  echo $taille
}

#-------------------------------------------------------------------------------------
# Déclaration des variables
#-------------------------------------------------------------------------------------

# Paramètres d&#039;identification de la clef
DEVTYPE=&quot;usb&quot;
ID_SERIAL_SHORT=&quot;A500000000026452&quot;
KEY_SYNC=/dev/LiveUSB2


# Répertoires sources et destination
SRC_DIR=/home/leseb/MOUNT/
DEST_DIR=/home/leseb/udevsync/
MONT_POINT=/home/leseb/MOUNT/

# Fichiers de log horodatés
BKP_DATE=`date +&quot;%Y-%m-%d_%H-%M&quot;`
LOG_FILE=/tmp/Logs_Sync/sdBackup_${BKP_DATE}.log
BKP_LOG_FILE=$DEST_DIR/Logs_Sync/sdBackup_${BKP_DATE}.log
RSYNC_ERR=/tmp/rsync.err


#------------------------------------------------------------------------------------
# Algo
#------------------------------------------------------------------------------------

# Initialisation du fichier de log
echo &quot;Backup du $BKP_DATE&quot; &gt;&gt; $LOG_FILE
echo &quot;Début à `date +&#039;%H:%M:%S&#039;`&quot; &gt;&gt; $LOG_FILE

if [ &quot;$ACTION&quot; = &quot;add&quot; ] ; then
	mount $KEY_SYNC $MONT_POINT
	echo &quot;Clef &quot;$ID_MODEL&quot; montée (&quot;$ACTION&quot;), backup en cours&quot; &gt;&gt; $LOG_FILE

	echo &quot;0&quot; &gt; nb
    	DEBUT=$(date +%s)

	rsync -p -r $SRC_DIR &quot;$DEST_DIR&quot; 

    	$SRC_DIR/ $DEST_DIR 2&gt;&gt;$RSYNC_ERR | sed &#039;
    	/to-check=/! {
     	/^sending/  {d;q;}
        /\/$/       {d;q;}
        /^sent/     {s/^.*$/echo &quot;&amp;&quot; \&gt;\/tmp\/rapport\.txt/e;d;q;};
        /^total/    {s/^.*$/echo &quot;&amp;&quot; \&gt;\&gt;\/tmp\/rapport\.txt/e;d;q;};
        /^.\{43\}/  {s/\(^.\{20\}\).*\(.\{20\}$\)/echo \$\(\(\$\(cat nb\) + 1\)\) \&gt; nb; echo &quot;\1\[...\]\2&quot; \&gt;\/tmp\/svgrd_sed\.txt/e;d;q;};
        /^.\{43\}/! {s/^.*$/echo \$\(\(\$\(cat nb\) + 1\)\) \&gt; nb; echo &quot;&amp;&quot; \&gt;\/tmp\/svgrd_sed\.txt/e;d;q;};
    	}
   	/to-check=/ {
     	s/.*=\(.*\)\/\(.*\))/echo &quot;#`echo &quot;scale=2;\(\2-\1\)\*100\/\2&quot; | bc | cut -d\. -f1`% (\$\(\(\2 - \1\)\) fichiers sur \2\) &gt; \$\(cat \/tmp\/svgrd_sed\.txt\)&quot;\; echo &quot;scale=2;\(\2-\1\)\*100\/\2&quot; | bc/e
    	}
   	&#039; | zenity --progress --width=580 --title=&quot;Home - synchronisation&quot; --text=&quot;Initialisation de la sauvegarde...&quot; --percentage=0 --auto-close &amp;

	    	while true; do
	      	sleep 1
	      		if [ -z &quot;$(pidof zenity)&quot; ]; then
				pkill rsync
	       			break
	      		fi
	    	done

	FIN=$(date +%s)
	TEMPS=$(($FIN-$DEBUT))
	TP_HEU=$(sed &#039;s/^.$/0&amp;/&#039; &lt;&lt;&lt; $(($TEMPS/3600)))
	TP_TMP=$(($TEMPS%3600))
	TP_MIN=$(sed &#039;s/^.$/0&amp;/&#039; &lt;&lt;&lt; $(($TP_TMP/60)))
	TP_SEC=$(sed &#039;s/^.$/0&amp;/&#039; &lt;&lt;&lt; $(($TP_TMP%60)))
	TP=$(echo &quot;$TP_HEU:$TP_MIN:$TP_SEC&quot;)

	ERR=$(cat $RSYNC_ERR)
	if [[ ${#ERR} -ne 0 ]]; then
		zenity --error --title=&quot;svgrd&quot; --text=&quot;Problème lors de la sauvegarde du répertoire &lt;b&gt;$SRC&lt;/b&gt;.\n\n&lt;b&gt;&lt;span color=&#039;red&#039;&gt;$ERR&lt;/span&gt;&lt;/b&gt;.&quot;
		rm $RSYNC_ERR
	else
		NB_FICH=$(cat nb)
		ENVOI=$(afficheTaille $(cat /tmp/rapport.txt | grep sent | cut -d&#039; &#039; -f2))
		RECU=$(afficheTaille $(cat /tmp/rapport.txt | grep sent | cut -d&#039; &#039; -f6))
		VITESS=$(afficheTaille $(cat /tmp/rapport.txt | grep sent | cut -d&#039; &#039; -f9))
		zenity --info --title=&quot;svgrd&quot; --text=&quot;Sauvegarde du répertoire\n&lt;b&gt;$SRC&lt;/b&gt;\nefféctuée avec succès.\n$NB_FICH fichiers synchronisés\n\nEnvoyé:\t$ENVOI\nReçu:\t$RECU\nTemps:\t$TP\nTransfert:\t$VITESS/sec&quot;
		rm nb
	fi	

	# Copie du log sur le répertoire de synchro
	cp -f $LOG_FILE $BKP_LOG_FILE

fi

if [ &quot;$ACTION&quot; = &quot;remove&quot; ] ; then
	umount -f $KEY_SYNC &gt;&gt; $LOG_FILE
	echo &quot;Clef &quot;$ID_MODEL&quot; démontée (&quot;$ACTION&quot;)&quot; &gt;&gt; $LOG_FILE
fi

#------------------------------------------------------------------------------------
# EOF
#------------------------------------------------------------------------------------</code></pre></div><p>La partie qui ne fonctionne pas et la partie de l&#039;affichage de la barre de progression et je capte pas vraiment pourquoi. Sinon la clef se monte bien et la synchro nickel.</p><p>Merci d&#039;avance à tous <img src="http://forum.ubuntu-fr.org/img/smilies/smile.png" width="15" height="15" alt="smile" /></p>]]></description>
			<author><![CDATA[dummy@example.com (RastaYoupi)]]></author>
			<pubDate>Fri, 29 Jan 2010 19:57:39 +0000</pubDate>
			<guid>http://forum.ubuntu-fr.org/viewtopic.php?pid=3245662#p3245662</guid>
		</item>
	</channel>
</rss>
