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

Re: [riminilug-general] Programma per controllare le modifiche inuna directory



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Monday 24 May 2004 16:50, Alessandro Carichini wrote:
non trovo la mail originale, e non ho tempo di cercarla.
osservate, e capite gli script.

google dnotify

zolfo:/etc# cat /root/check_dir
#!/bin/bash
(
echo "To: sysadmin"
echo "From: Zolfo"
echo "Subject: zolfo: cd"

DIR_INCOMING="/home/scponly/incoming"
DIR_BACKUP="/var/backups/scponly"
DIR_TEMP="/tmp/scponly"
RECORD=/root/record_when_done
while(true)
do      fuser ${DIR_INCOMING}/* > /dev/null
        if [ $? -eq 1 ]
        then    # prima muovere i file, poi copiarli
                DATE=`date +%d_%m_%Y-%H_%M_%S`
                mkdir -p ${DIR_TEMP}/${DATE}
                mv ${DIR_INCOMING}/* ${DIR_TEMP}/${DATE}
                for i in `ls -t ${DIR_TEMP}/${DATE}` ; do ln -sf 
${DIR_TEMP}/${DATE}/${i} ${DIR_TEMP}/${i} ; done
                mkisofs -J -r -o ${DIR_TEMP}.iso ${DIR_TEMP}/ # 2>&1
                mkdir -p $DIR_BACKUP
                mv ${DIR_TEMP}/* ${DIR_BACKUP}
                ${RECORD} ${DIR_TEMP}.iso # 2>&1
                break
        else    sleep 10
        fi
done
) 2>&1 | /usr/lib/sendmail -t
zolfo:/etc# cat /root/record_when_done
#!/bin/sh
CDRECORD="`which cdrecord` dev=0,0,0"
FILENAME=$@
GREP_STRING="WARNING: Data may not fit on current disk."

if [ $# -eq 0 ] ; then echo usage: $0 iso ; exit 1 ; fi
while(true)
do      PID=`pidof cdrecord.mmap` #> /dev/null
        if [[ "$PID" != "" ]]
        then    sleep 10s
                continue
        fi

        # check for media
        $CDRECORD -atip #2>&1 > /dev/null
        if [[ $? -ne 0 ]] ; then # se l'exit code e` != 0, errore
                echo "CD NOT PRESENT OR CD ERROR"
                exit 1
        fi

        #  run
        RUN="${CDRECORD} -multi driveropts=burnfree ${FILENAME}"
        LOG=`$RUN` #2>&1`
        EXIT_CODE=$?
        GREP_LOG=`echo ${LOG} | grep "${GREP_STRING}"`
        if [[ "${GREP_LOG}" != "" ]] ; then
                echo "ISO TOO BIG"
                echo "CHANGE CD (EVENTUALLY FIX IT) AND RUN:"
                echo "$RUN && rm $FILENAME"
                exit 1
        elif [[ $EXIT_CODE -ne 0 ]] ; then
                echo "GENERIC ERROR: CHECK LOG"
                echo $LOG
                exit 1
        else
                echo rm $FILENAME
        fi
        break;
done
zolfo:/etc# cat /root/comando
dnotify -C /home/scponly/incoming --processes 1 -e /home/check_dir
date +%d_%m_%Y-%H_%M_%S
cdrecord dev=ATAPI:0,1,0 -multi
zolfo:/etc# cat /root/prova.sh
#!/bin/sh
LOG=`cdrecord dev=0,0,0 -dummy -multi driveropts=burnfree /tmp/isosmall.iso 
2>&1`
echo $LOG
GREP_STRING="WARNING: Data may not fit on current disk."
GREP_LOG=`echo $LOG | grep "${GREP_STRING}"`
if [[ "${GREP_LOG}" != "" ]] ; then
        echo non_fit
fi
#cdrecord dev=0,0,0 -atip
echo $?
zolfo:/etc#

- -- 
PGP Key-ID: 0xF482D454
- --
To bodly go where no man has gone before.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFAsgOY8Tj5mfSC1FQRAmG8AJ94n+tjqFiTWIS2xB3mQsORWunGhwCfb5yR
83xIBqh0801enn6HO8jnRc4=
=Saer
-----END PGP SIGNATURE-----