Saltar al contenido

~ / archivo / stackoverflow / 51387990

Exclude a folder in a script that checks for file changes?

StackOverflow · file, cron, cron-task · ayudé
  1. Alex pregunta 2018-07-17 18:20

    I have a cronjob that runs every 24 hours to tell me if files on my server have changed. The script is as such:

    find /home/bsc1933 -type f -ctime -1 -exec ls -ls {} \; | mail -E -s “File Changes, Past 24 Hours” myemail
    

    I would like to modify it to exclude a specific folder, in this case my cache folder: /home/bsc1933/public_html/cache

    I found the original script with Google-fu and just edited the email to match mine, so my knowledge of actually editing the script itself is non-existent. Could someone help me?

  2. Miguel Ortiz yo respuesta 2018-07-17 18:27

    Try using grep or find to ignore entries with a certain pattern.

    With grep:

    find /home/bsc1933 -type f -ctime -1 -exec ls -ls {} \; |grep -Ev  "/home/bsc1933/public_html/cache" | mail -E -s “File Changes, Past 24 Hours” myemail
    

    Or telling find to ignore it:

    find /home/bsc1933 ! -path '*/.cache/*' -type f -ctime -1 -exec ls -ls {} \; | mail -E -s “File Changes, Past 24 Hours” myemail
    
  3. Kishan Parekh respuesta 2018-07-17 18:43

    Simplest answer is as follows, by adding "grep" to filter out path you wish to exclude, between "find" and "mail" command.

    `find /home/bsc1933 -type f -ctime -1 -exec ls -ls {} \; | grep -v '/home/bsc1933/public_html/cache' |` ... your code to send email ...
    

    Let me know if you face any other difficulties.

← todos los hilos de StackOverflow