Raspberry-Pi-Installer-Scripts icon indicating copy to clipboard operation
Raspberry-Pi-Installer-Scripts copied to clipboard

Crontab not working

Open MeMattStone opened this issue 7 years ago • 12 comments

Apologies in advance if I've missed something really obvious on this one but on two seperate installs I'm having a problem with crontabs, everything works fine until I run the script to setup as read-only, after this none of my cron jobs are running (everything was setup prior to running the Adafruit script) and typing crontab -e for the pi user or sudo crontab -e to run as root lets me create a crontab but on reboot these crontabs are lost. Obviously when I try to create these crontabs again I have a jumper on GPIO21 so that the the filesystem is mounted as writeable.

MeMattStone avatar Oct 21 '18 14:10 MeMattStone

hiya which script is this you're referring to?

ladyada avatar Oct 21 '18 18:10 ladyada

Sorry, the script in question is read-only-fs.sh

MeMattStone avatar Oct 22 '18 06:10 MeMattStone

hmm, you could check error logs but it sounds like a linux thing not an issue/mistake with the script, so we're not sure how to fix - we haven't done any testing with the script + chron!

ladyada avatar Oct 22 '18 07:10 ladyada

I got to the bottom of this, lines 264-266 move the location of /var/spool to the /tmp location and crontabs get written to /var/spool/cron/crontabs which will get deleted by the read only script. The workaround for this is to use the system cron at /etc/crontab which has a slightly different format as you have to specify the user account before the command but otherwise works fine. I'm guessing the longer term fix would be to symlink /var/spool/cron to another folder and move and existing contents before deleting the /var/spool folder, not sure if it's possible to symlink inside a symlink? If not the system cron is the answer. Hope this helps anyone else who has had this issue with crontabs.

MeMattStone avatar Oct 27 '18 12:10 MeMattStone

@PaintYourDragon make a note in the guide?

ladyada avatar Oct 27 '18 22:10 ladyada

https://forums.adafruit.com/viewtopic.php?f=8&t=143442

ladyada avatar Nov 12 '18 19:11 ladyada

I have precise the same issue

as a workaround i go in Write mode and create the crontabs and them copy them to /home/pi/

and then i add to /etc/rc.local before final exit:

sudo cp /home/pi/pi /var/spool/cron/crontabs/pi sudo cp /home/pi/root /var/spool/cron/crontabs/root

it's a very rough hack at best

i think @MeMattStone is on to something

boelle avatar Nov 12 '18 19:11 boelle

What about using /etc/cron.d? Normally for root crontabs, but maybe we can bend that rule for the sake of read-only-ism.

PaintYourDragon avatar Nov 13 '18 04:11 PaintYourDragon

if it can get the job done for both root and pi user then i have protest against it

those that allready have the script what would they do?

boelle avatar Nov 13 '18 11:11 boelle

TBH it's a bit out of my league, being only an occasional Linux user. Really didn't expect the script would be used on anything more advanced than a RetroPie setup or some Halloween eyes.

Short term, I'm going to document this aspect better so others won't be led into believing it's a robust solution to anything. Longer term, if anyone has a solid workaround for the script to handle this better, I'd gladly merge it.

PaintYourDragon avatar Nov 14 '18 04:11 PaintYourDragon

well the reason i use it is that every other guide failed, and by failed i mean that there was an error at boot i could not figure and it prevented me from ssh to the pi

this was about the ony thing that made it read-only and allowed me access

no hard feelings from my side. i'm also an occasional Linux user and i know that has it limits.

maybe @ladyada & Co knows somebody that knows how we could make it better

boelle avatar Nov 14 '18 10:11 boelle

we don't know who could do this in house - if we did we'd have em fix it! if you know someone please point them to this repo :)

ladyada avatar Nov 14 '18 16:11 ladyada