~ / archivo / stackoverflow / 51387990
Exclude a folder in a script that checks for file changes?
StackOverflow
· file, cron, cron-task
· ayudé
-
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” myemailI would like to modify it to exclude a specific folder, in this case my cache folder:
/home/bsc1933/public_html/cacheI 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?
-
Try using
greporfindto 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” myemailOr 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 -
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.