The UNIX and Linux Forums  


Go Back   UNIX e Linux Forum > Inizio Forum > Shell scripting e di programmazione
.
google unix.com



Shell scripting e di programmazione Pubblica domande su KSH, CSH, SH, Bash, Perl, PHP, sed, awk e da altri script di shell e linguaggi di scripting shell qui.

Più di UNIX e Linux Forum Argomenti potreste trovare utili
Filo Thread Starter Forum Risposte Ultimo Post
chmod ricorsivo che riguarda solo le directory? retrovertigo UNIX e avanzata per utenti esperti 1 06-22-2007 05:02 PM
Sottodirectory pid script jbarnhar Shell scripting e di programmazione 3 05-02-2007 04:14 PM
Problema con funzione ricorsiva malle Shell scripting e di programmazione 4 02-03-2007 10:40 AM
directory problema yeah016 UNIX for Dummies Domande & Risposte 2 07-22-2006 08:48 AM
grep ricorsiva directory jagannatha UNIX for Dummies Domande & Risposte 8 07-24-2003 05:00 PM

 
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Cerca in questo Thread Rate Thread Modalità di visualizzazione
  #1 (permalink)  
Old 04-27-2008
robertmcol robertmcol is offline
Utente Registrato
  
 

Iscriviti Data: febbraio 2008
Interventi: 6
Script problema dovuto alla directory ricorsive Aiuto per favore

Ciao a tutti, sto cercando una soluzione migliore allora quella che ho creato per il mio compito

Il compito è:
Crea uno script automatizzati che si verifica per Caricamenti in una directory specificata e spostarli in un'altra directory specificata, se i file sono completamente caricato.

I file vengono FTP'd alla directory specificata
FTPS multipli potrebbe essere in esecuzione in modo sapere se un particolare FTP è completo, è difficile per me, per controllare da ID del processo


Ho creato lo script elencati qui sotto, ma può vedere che i problemi possono sorgere con Uploads di Alberi
per esempio
Se il caricamento ha le seguenti directory:

Citazione:
# Ls-l UPLOAD_DIR /
UPLOAD_DIR /:
totale 4
drwxr-xr-x 4 root root 4096 apr 26 21:32 Directory1
-rw-r - r - 1 root root 0 apr 26 21:31 file1.txt

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

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

UPLOAD_DIR/Directory1/SubDir1:
totale 0
-rw-r - r - 1 root root 0 apr 26 21:32 subdir1file2.txt
-rw-r - r - 1 root root 0 apr 26 21:32 subdir1file1.txt
Non sono sicuro, ma se l'ultimo modificata stat data di comando su una directory di età è quindi l'età Sto cercando
poi dovresti; t che significa
che qualsiasi tipo di file e directory sotto al di sotto di tale directory sarà completamente caricato e quindi anche per le vecchie Age che sto cercando?
...... Mi auguro che avevano un senso ....
Non credo che se è il caso ....

Mi auguro ci sia un modo migliore per affrontare questo problema.

Grazie per essere qui.


Codice:
#!/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

 

Segnalibri

Thread Tools Cerca in questo Thread
Cerca in questo Thread:

Ricerca Avanzata
Modalità di visualizzazione Vota questo thread
Vota questo thread:

Distacco regolamento
Tu non può post nuovo thread
Tu non può inviare una risposta
Tu non può postare allegati
Tu non può modificare i tuoi post

BB codice è Su
Smilies sono Su
[IMG] codice Su
Codice HTML è Chiuso
Trackbacks sono Su
Pingbacks sono Su
Refbacks sono Su




Tutti gli orari sono GMT -4. La data di oggi è 03:48 AM.


Powered by: vBulletin, Copyright © 2000 - 2006, Jelsoft Enterprises Limited. Traduzioni Powered by .
vBCredits v1.4 Copyright © 2007 - 2008, PixelFX Studios
UNIX e Linux Forum Content Copyright © 1993-2009. Tutti i diritti Reserved.Ad di gestione da RedTyger

Contenuti pertinenti URL da vBSEO 3.2.0