[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [linux-team] Regexp en ligne de commande



On Mon, Oct 25, 1999 at 03:55:54PM +0200, Christophe Schockaert wrote:
> Je voudrais faire un backup du home directory de mes users: j'ai fait un
> cron qui devrait lancer la ligne suivante:
> find /home -mindepth 1 -maxdepth 1 -exec tar -uvzf /backup/{}.tgz {} \;
> mais je voudrais faire une regexp sur le premier paramètre pour n'en
> conserver que la fin.
> En effet, la commande 
> 
> find /home -mindepth 1 -maxdepth 1 -exec echo {} \;  
> 
> affiche:
> /home/chris
> /home/paul
> ...
> 
> et j'aimerais bien que mes fichiers archives soient
> /backup/chris.tgz
> /backup/paul.tgz 
> ...
> 
> plutôt que
> /backup/home/chris.tgz
> ...

find /home/* -type d -prune \
| sed 's+^/home/++' \
| while read user
do
	 tar czf /backup/${user}.tar.gz /home/$user
done
  
[...]
> Je crois que c'est pas trop compliqué à faire, mais qu'il faut juste
> connaître le truc. 
De fait, mais le find en soi ne peut faire que la moitié du boulot.
Avec une boucle while, le tout est beaucoup plus facile à faire :)

Si tu veux faire un backup journalier et créer une nouvelle archive à
chaque fois:

find /home/* -type d -prune \
| sed 's+^/home/++' \
| while read user
do
	 DIRNAME=/backup/`date '+%b/%d'`
	 mkdir -p $DIRNAME
	 tar czf $DIRNAME/${user}.tar.gz /home/$user
done
 
> Toute aide est la bienvenue,
Ca te va, comme ça ? :)

-- 
  -o)  Pascal Bleser        | Instead of giving  Windows
  /\\  C++/UNIX Development | the "three-finger-salute",
 _\_v  ATOS Payment Systems | give it  the  "one-finger-
       Aachen, Germany      | goodbye"  {jfk/propaganda}   
<pbleser@atos-group.com>--------------<guru@linuxbe.org>

---------
Visit the Linux Supertore Online: http://www.redcorp.com !
If you want to be deleted from the list, send a mail to
majordomo@rtfm.be with "unsubscribe linux-team" in the body.
Archive of the list: http://tania.be.linux.org/