4

Good afternoon, I'm trying to edit by soft, as a text file, the file that contains the crontab data. This is because I need to execute a series of functions daily, they are related to the sunrise and sunset, which vary from day to day. The idea is to generate today the crontab file, with the morning schedule, save it and tomorrow when the system starts it will do so with the corresponding data. I can not find the file, and what I find the system does not allow me to edit ...

Thank you

0

3 Answers 3

8

If you want to run cron jobs with start times relative to sun up/down or twilight then you could use sunwait It will determine the correct time to wait, based on your location's coordinates.

Simple example running echo 1 hour before sunrise:

 # m h  dom mon dow   command
 01 00   *   *   *  /usr/local/bin/sunwait sun up -1:00:00 52.518N 1.475W; /bin/echo "hello"
5

I tried sunwait, mentioned above, but found it to be a bit clunky. I rewrote a similar program, myself, called heliocron, with the advantages being that it is actively maintained, has clear documentation and even has prebuilt binaries that run on Raspberry Pis off the bat.

A basic command might look something like:

0 2 * * * heliocron --latitude 51.4769N --longitude 0.0005W wait --event sunrise --offset -00:30 && turn-on-lights.sh

Full documentation in the GitHub repo: https://github.com/mfreeborn/heliocron

1
  • sunwait is also actively maintained.
    – user10489
    Mar 25 at 4:14
-1

The crontab files are located at /var/spool/cron/crontabs/.

You will need to be root to access them, e.g.

sudo su
cd /var/spool/cron/crontabs
leafpad pi

Be aware that if you make any mistakes, that particular crontab will no longer function.

1
  • 4
    No need to be root to access a user's own crontab. Type 'crontab -e' to edit that user's own crontab file. Jul 5, 2020 at 16:57

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.