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

6

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"
| improve this answer | |
3

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

| improve this answer | |
New contributor
Michael Freeborn is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
0

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.

| improve this answer | |
  • 3
    No need to be root to access a user's own crontab. Type 'crontab -e' to edit that user's own crontab file. – Tim Campbell Jul 5 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.