0

I have a website on a hosting provider, which allows cron jobs to be set up via cpanel. I have the below cron job set up. The problem is it is returning 'No Changes' when I know there are changes in /home/myusername/public_html within the last 24 hours.

If I log into cpanel manually to test this job It does show changes because the act of logging in changes a lot of files within my root, so I can't really test reliably.

I'm trying to exclude the security folder because it comes up access denied in the output so I want a cleaner output. (Also I think the permission denied message is preventing the 'no changes found' condition from working when it's actually true.

So my question is, is there something wrong with the way I've constructed this cron job/shell command that is preventing it from taking the expected action (find changes in my root folder structure, including public_html, excluding .security)

findout=$(find  /home/myusername -path /home/myusername/.security -prune -o 
-type f -mtime -1   | egrep '.*') && (printf "Found Changes...\n\n $findout") || 
(printf "No Changes")

(the command is all one line but I have split it in the question for better readability)

  • The exit status of find indicates whether it had issues traversing the filesystem, not whether it found anything. – Patrick Feb 6 '18 at 13:23
  • @Patrick I know that. That's why the egrep is there. If egrep finds nothing then IT has an exit status of zero, which then determines whether to show 'No Changes' or 'Found Changes' – MrVimes Feb 6 '18 at 13:50
  • Please show the complete cron line. Is it in cron.daily or the like or in crontab? Did you check the CRONPATH? Did you try which find egrep printf? – user unknown Feb 6 '18 at 17:17
  • I don't have access to the cron file as it's a hosted package. I paste the command into a line in cpanel, and include a time to run it. It runs fine. It just doesn't give the expected output when there have been changes to the folder structure. There's nothing wrong with the cron aspect. The problem is with the command not doing what I thought it would do based on how I've constructed it. – MrVimes Feb 6 '18 at 17:24
  • And do you know, whether egrep exists? I don't have CentOs, and on my machine, the egrep doesn't make a difference. You could try it without - maybe egrep isn't installed? – user unknown Feb 6 '18 at 17:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.