shell-script-pt
[Top][All Lists]
Advanced

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

Re: [shell-script] chmod stat atime ctime mtime


From: Jorge Barros de Abreu
Subject: Re: [shell-script] chmod stat atime ctime mtime
Date: Tue, 6 Dec 2011 20:21:52 -0200
User-agent: KMail/1.13.6 (Linux/2.6.37.6; KDE/4.5.5; x86_64; ; )

O script completo é mostrado abaixo.
O y é gerado a partir de um relatório do aide.
Retira-se o caminho completo e o atime/mtime/ctime

Geralmente corrige-se apenas o atime e o mtime. No script abaixo "corrige-se" 
também o ctime. O 
corrije-se aqui deve ser interpretado como "minimização dos prejuísos", uma vez 
que as datas 
originais foram perdidas. Apenas coloca-se a hora atual evitando aqueles avisos 
de data no futuro e 
aqueles arquivos irremediávelmente e eternamenteno topo da lista quando 
ordenando-se por data.

A versão abaixo corrige inclusive links simbólicos que precisam de ajuste 
diferenciado.

A versão final do script ficou assim:

#!/bin/bash
#-------------------------
#atime  | ctime  |  mtime
#-------|--------|--------
#ls -lu | ls -lc |  ls -l
#-------|--------|--------
#access | change |  modify
#arquivo| inode  |  arquivo
#-------|--------|--------
#touch  | chmod  |  touch
#--------------------------
oFS=$IFS
IFS=';'
for i in `cat y | tr '\n' ';'`
do
IFS=' '
ARQUIVO=`echo $i | cut -d' ' -f1` #pode ser um nome de diretorio
PARAMETRO=`echo $i | cut -d' ' -f2`
if [ -e $ARQUIVO ]
    then
    if [[ $PARAMETRO == "atime" ]]
            then
                if [ -h $ARQUIVO ]
                    then
                        touch -h --time=atime $ARQUIVO
                    else touch --time=atime $ARQUIVO
                fi
    fi
    if [[ $PARAMETRO == "ctime" ]]
            then
                OCTAL=`stat -c '%a' $ARQUIVO`
                chmod $OCTAL $ARQUIVO
    fi
    if [[ $PARAMETRO == "mtime" ]]
            then
                if [ -h $ARQUIVO ]
                    then
                        touch -h --time=mtime $ARQUIVO
                    else touch --time=mtime $ARQUIVO
                fi
    fi
fi
IFS=';'
done
IFS=$oFS


-- 
Data Estelar 2455902,427419
http://sites.google.com/site/ficmatinf
Desejo-lhe Paz, Vida Longa e Prosperidade.
São Bem Vindas Mensagens no Formato texto UTF-8 com Acentos.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]