The UNIX and Linux Forums  


Go Back   O UNIX e Linux Forum > Top Fóruns > Programação Shell Script e
.
google unix.com



Programação Shell Script e Post perguntas sobre ksh, CSH, SH, BASH, Perl, PHP, SED, Awk e outros scripts shell e shell scripts línguas aqui.

Mais UNIX e Linux Fórum Tópicos Você pode achar Helpfull
Fio Thread Starter Fórum Respostas Última postagem
chmod recursivo diretórios que só afeta? retrovertigo UNIX & avançada para usuários experientes 1 06-22-2007 05:02
Recursivo pid script jbarnhar Programação Shell Script e 3 05-02-2007 04:14
Problema com função Recursiva malle Programação Shell Script e 4 02-03-2007 10:40
diretórios problema yeah016 UNIX para Dummies Perguntas & Respostas 2 07-22-2006 08:48
grep recursivo diretórios jagannatha UNIX para Dummies Perguntas & Respostas 8 07-24-2003 05:00

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
Linkback Thread Tools Pesquisar este Thread Rate Thread Display Modes
  #1 (permalink)  
Old 04-27-2008
robertmcol robertmcol is offline
Usuário
  
 

Join Date: Feb 2008
Posts: 6
Script problema devido ao recursivas diretórios Ajuda por favor

Olá a todos, estou procurando uma melhor solução, então o que tenho um criado para a minha tarefa

A tarefa é:
Criar um script automatizado que irá verificar se há Uploads em um diretório especificado e movê-los para outro diretório especificado se os arquivos estão completamente carregadas.

Os arquivos são FTP'd para o diretório especificado
Múltiplas FTPS poderia estar correndo assim saber se um determinado FTP está completa é difícil para mim verificar pelo ID do processo


Eu criei o script abaixo listados, mas pode ver que problemas podem surgir com uploads de Árvores
por exemplo
Se o diretório upload tem a seguinte:

Citação:
# Ls-ltr UPLOAD_DIR /
UPLOAD_DIR /:
total 4
drwxr-xr-x 4 root root 4096 26 abr 21:32 Directory1
-rw-r - r - 1 root root 0 26 abr 21:31 file1.txt

UPLOAD_DIR/Directory1:
total 8
drwxr-xr-x 2 root root 4096 26 abr 21:33 SubDir2
drwxr-xr-x 2 root root 4096 26 abr 21:32 Subdir1
-rw-r - r - 1 root root 0 26 abr 21:32 dir1file1.txt

UPLOAD_DIR/Directory1/SubDir2:
Total 0
-rw-r - r - 1 root root 0 26 abr 21:33 subdir2file2.txt
-rw-r - r - 1 root root 0 26 abr 21:33 subdir2file1.txt

UPLOAD_DIR/Directory1/SubDir1:
Total 0
-rw-r - r - 1 root root 0 26 abr 21:32 subdir1file2.txt
-rw-r - r - 1 root root 0 26 abr 21:32 subdir1file1.txt
Não tenho certeza, mas se mudou a última data do stat comando em um diretório é mais que a idade que eu estou procurando
então devia, não significa que
que qualquer ficheiro e sub-diretórios abaixo desse diretório será completamente carregado e também o mais velho, então Idade estou procurando?
...... Espero que faz sentido ....
Penso que não é o caso embora ....

Estou esperando há uma maneira melhor de lidar com esta questão.

Obrigado por estar aqui.

Código:
#!/bin/bash
#
#
# This script will be used to monitor uploads to a specified directory
# and move them to another directory for downloading.
#
# Things to consider:
#       1. Was the uploaded files uploaded in a sub directory.
#       2. Are the files being uploaded complete.
#       3. Move the files to the specified directory
#          with the proper permissions.
#
#
#-------------------------------------------------------------------------------#
#
# Functions
#
#-------------------------------------------------------------------------------#
calc_time() {
        AGE_LAST_CHANGED=`expr ${CURRTIME} - ${FILE_LAST_CHANGED}`
        if [ ${AGE_LAST_CHANGED} -lt ${ACCEPTED_AGE} ];
        then
                OK_TO_MOVE=N
        else
                OK_TO_MOVE=Y
        fi
}
check_date() {
        FILE_LAST_CHANGED=`stat -t ${NEWFILE} |awk '{print $13}'`
}
#-------------------------------------------------------------------------------#
#
# Vairables will go here
#
#-------------------------------------------------------------------------------#
UPUSER=up_user
DOWNUSER=down_user
#
UPPATH=/home/Private/Uploads
DOWNPATH=/home/Private/Downloads

CURRTIME=`date +%s`
ACCEPTED_AGE=300        # 5 minutes of no activity according to date modified


for f in $( ls ${UPPATH} ); do

if [ -d ${UPPATH}/${f} ];
then
#--- Directory with Subfiles In it ---#
        DIR=${UPPATH}/${f}
        echo "${DIR} is a Directory"
        DIRDATE=`date +%Y_%m_%d_%H%M%S`
        NEWDIR=${DOWNPATH}/${f}_${DIRDATE}
        NEWFILE=${DIR}
        check_date
        calc_time
                # It appears that the directory has not been changed in the allowed timeframe (ACCEPTED_AGE)
                # it is ok to create a new directory in the DOWNPATH now.
                # set permissions of new directory to the download user
        mkdir ${NEWDIR}

        # This causes a problem by leaving the original Directory present in th UPLOADS directory.

        for f2 in $(ls  ${UPPATH}/$f ); do
                NEWFILE=${DIR}/${f2} # Set becuase of check_date function
                check_date
                calc_time
                if [ ${OK_TO_MOVE} = "Y" ];
                then
                        mv ${NEWFILE} ${NEWDIR}
                        echo "mv ${NEWFILE} ${NEWDIR} "
                else
                        echo "File date is too new to move better wait"
                fi

        chown -R ${DOWNUSER}:${DOWNUSER} ${NEWDIR}
        done

else
#--- File is in Main Upload directory ---#
        if [ -f ${UPPATH}/$f ]; then
                NEWFILE=${UPPATH}/${f}
                echo "${NEWFILE} is a file"
                check_date
                calc_time

                if [ ${OK_TO_MOVE} = "Y" ];
                then
                        mv ${NEWFILE} ${DOWNPATH}
                        echo "mv ${NEWFILE} ${DOWNPATH} "
                        chown ${DOWNUSER}:${DOWNUSER} ${DOWNPATH}/*
                else
                        echo "File date is too new to move better wait"
                        echo "next pass of cronjob should move this file"
                fi
        fi
fi

done
 

Marcadores

Thread Tools Pesquisar este Thread
Pesquisar este Thread:

Pesquisa Avançada
Display Modes Esta taxa Thread
Esta taxa Thread:

Destacamento Regimento
Você não pode postar novas threads
Você não pode postar respostas
Você não pode postar anexos
Você não pode editar suas postagens

BB code é Ligado
Smilies são Ligado
[IMG] código é Ligado
Código HTML é Desligado
Trackbacks são Ligado
Pingbacks são Ligado
Refbacks são Ligado




Todos os horários são GMT -4. A hora é agora 09:05.


Powered by: vBulletinCopyright © 2000 - 2006, Jelsoft Enterprises Limited. Língua Traduções Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
O UNIX e Linux Fóruns Content Copyright © 1993-2009. Todos os Direitos Reserved.Ad Gestão por RedTyger

Content Relevant URLs por vBSEO 3.2.0