1

I was going through previous questions, and I guess my enviromental variables are wrong. But how can I fix it..

I want to execute a .sh file every 2 hours which contains this content:

#!/bin/bash
find /directory -type f -print0 | xargs -0 chmod 666
find /directory -type d -print0 | xargs -0 chmod 755

But when cron is supposed to run it as root it just doesn't execute it, but manually it does?

Thanks in advance!

Sebastian
  • 363
  • 3
  • 14
  • Add your cron entry. – Cyrus May 30 '15 at 07:10
  • In /etc/crontab: * */2 * * * root /root/file.sh – Sebastian May 30 '15 at 07:26
  • Have you tried to restart your cron? – Cyrus May 30 '15 at 07:39
  • Please read this question for that: http://stackoverflow.com/questions/10193788/restarting-cron-after-changing-crontab-file – Sebastian May 30 '15 at 15:23
  • 1
    Well sprry, I guess that was the problem. I though cron reads it automatically.. without restarting the service mhh :P – Sebastian May 30 '15 at 15:47
  • Vixie cron (used by Ubuntu and Red Hat Enterprise Linux) is old but not perfect. – Cyrus May 31 '15 at 06:30
  • I just wonder, with so many [similar issues](http://stackoverflow.com/questions/10193788/restarting-cron-after-changing-crontab-file) why have they not modified the content for `man cron`? _...cron need not be restarted whenever a crontab file is modified..._ – tjeloep Jun 02 '15 at 02:15

1 Answers1

1

Crontab has not to be restarted. Especially if you edit your crontob with the command crontab -e. Here the lines from man:

Additionally, cron checks each minute to see if its spool directory's modtime (or the modtime on the /etc/crontab file) has changed, and if it has, cron will then examine the modtime on all crontabs files and reload those which have changed. Thus cron need not be restarted whenever a crontab file is modified. Note that the crontab(1) command updates the modtime of the spool directory whenever it changes a crontab.

It is strange that a restart of the cron service solved your problem. Maybe you solved some other possible problems as missing permissions.

You can add the user (e.g. root) behind the time format sequence who should execute the command/script. Then this user should granted the permissions to execute the given command.

Important: The last line of the cron-file has to be an empty line or a comment line!

zypro
  • 1,158
  • 3
  • 12
  • 33