![]() |
|
|
google unix.com
|
|||||||
| Fóruns | Registar | Fórum Regimento | Ligações | Álbuns | FAQ | Lista deputados | Calendário | Pesquisa | Today's Posts | Mark Forums Read |
| 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 |
|
|
Linkback | Thread Tools | Pesquisar este Thread | Rate Thread | Display Modes |
|
||||
|
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:
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 |
| Display Modes | Esta taxa Thread |
|
|