Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[bash] monitorización archivos con inotify
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Spanish
View previous topic :: View next topic  
Author Message
Theasker
l33t
l33t


Joined: 18 Nov 2006
Posts: 656
Location: Zaragoza (Spain)

PostPosted: Fri Jul 12, 2013 1:46 pm    Post subject: [bash] monitorización archivos con inotify Reply with quote

Estoy haciendo un pequeño script para monitorizar los archivos de un servidor web y cada vez que se cree o modifique un archivo subirlo a un hosting para así crear un espejo de esa web.

Code:

#!/bin/bash

DIRBASE="/var/www/"

while OUTPUT=`inotifywait --format '%f' -rm -e create -e modify -e delete $DIRBASE`;do
   echo "El fichero ganador es $DIRBASE${OUTPUT}"
#   aqui van los comandos ftp para subir los archivos
done


para luego poder situar/eliminar el archivo cerado/modificado/borrado en su lugar tengo que saber la ruta absoluta o relativa respecto del directorio base, pero la opción --format '%f', sólo me muestra el archivo sin ruta y necesitaría la ruta completa o al menos la relativa desde el directoio base para poder acceder al archivo. No encuentro la opción en el man de inotifywait para sacar esa ruta.

Gracias anticipadas y un saludico
_________________
"Oigo y olvido. Veo y recuerdo. Hago y comprendo"
Back to top
View user's profile Send private message
quilosaq
Veteran
Veteran


Joined: 22 Dec 2009
Posts: 1522

PostPosted: Fri Jul 12, 2013 2:46 pm    Post subject: Reply with quote

¿Qué tal añadir %w?
Code:
while OUTPUT=`inotifywait --format '%w%f' -rm -e create -e modify -e delete $DIRBASE`;do
Back to top
View user's profile Send private message
Theasker
l33t
l33t


Joined: 18 Nov 2006
Posts: 656
Location: Zaragoza (Spain)

PostPosted: Fri Jul 12, 2013 8:47 pm    Post subject: Reply with quote

Vaya, tengo que mejorar mi inglés, no entendí bien lo que decía, igual debería haberlo probado. Esa era la opción.

Ahora a ver como adapto ese path absoluto del fichero para mandarlo a hosting.

Gracias y ... perdón por la falta de comprobación
_________________
"Oigo y olvido. Veo y recuerdo. Hago y comprendo"
Back to top
View user's profile Send private message
quilosaq
Veteran
Veteran


Joined: 22 Dec 2009
Posts: 1522

PostPosted: Fri Jul 12, 2013 10:34 pm    Post subject: Reply with quote

Aquí tienes un script de ejemplo que utiliza un cambio de path absoluto a relativo:
Code:
#!/bin/sh

# get the current path
CURPATH=`pwd`

inotifywait -mr --timefmt '%d/%m/%y %H:%M' --format '%T %w %f' \
-e close_write /tmp/test | while read date time dir file; do

       FILECHANGE=${dir}${file}
       # convert absolute path to relative
       FILECHANGEREL=`echo "$FILECHANGE" | sed 's_'$CURPATH'/__'`

       rsync --progress --relative -vrae 'ssh -p 22'  $FILECHANGEREL usernam@example.com:/backup/root/dir && \
       echo "At ${time} on ${date}, file $FILECHANGE was backed up via rsync"
done

Fuente:
https://github.com/rvoicilas/inotify-tools/wiki#wiki-info
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Spanish All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum