0

I created a script that will add a cron job based on user specifications but it won't work since I need to refresh cron every time I append a job in crontab. Is there a way to refresh cron without killing the process?

0
3

As long as your script uses crontab to add and delete job specifications for the user, there would be no need to restart the cron daemon.

The AIX 7.1 cron manual page says:

When you make changes to the crontab files using the crontab command, a message indicating the change is sent to the cron daemon.

See also the crontab manual.

The general flow of actions that your script would take:

  1. Get user's crontab into a text file using crontab -l >crontab.txt.
  2. Manipulate the text file by adding, removing or changing jobs specifications.
  3. Load the user's crontab with the new specifications using crontab crontab.txt.

The commands in the first and last steps needs to be executed as the user (the first step could also be run as crontab -l username >crontab.txt as e.g. root).

This would work on any Unix using cron.

2
  • What if there are existing jobs? Do I have to put it in the same text file first then append the new job before loading it in the crontab?
    – Shan
    Jul 3 '18 at 5:52
  • @Shan As I mentioned, you would get the current crontab for the user, then modify that before loading it again. So yes, you would append new jobs to the file produced by crontab -l.
    – Kusalananda
    Jul 3 '18 at 5:53
-1

AIX 7.1 cron manual page says:

The cron daemon reads the configuration file when it is activated and when it receives the hangup signal.

So just kill -HUP cron_pid should do it.

5
  • I already tried this but I would like to refresh my configuration without killing the process
    – Shan
    Jul 3 '18 at 5:45
  • @Shan The kill command sends signals to the process. In general, processes can be killed, i.e., they actually die, by receiving a signal. But in case of cron process it handles the signal, does not die, and re-reads its configuration.
    – wilx
    Jul 3 '18 at 5:49
  • 2
    The portion of the man page that you quoted is referring to cron's configuration file, /etc/cronlog.conf, not the crontab files themselves.
    – Jeff Schaller
    Jul 3 '18 at 12:59
  • 1
    I cannot make this into an Answer for this question; when I manually edit a crontab file and HUP cron, the new cron job is not executed.
    – Jeff Schaller
    Jul 3 '18 at 13:35
  • @JeffSchaller is correct, you either have to kill -9 cron_pid or use crontab on a crontab file as suggested by Kusalananda in the other answer to reload the crontab.
    – doktor5000
    Jul 7 '18 at 9:44

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.