Requirements
Root access: for superuser commads like reboot, or init.d config. Crond can still run under normal user privs.
Busybox: for 'crond' service
(Optional) init.d support: to start 'crond' service at boot. Or start via Magisk post-fs-data.d script.
Creating cronjob
Create the cronjob file in directory /data/crontab/ (it could be any accessible directory even in sdcard) with filename 'root'.
Write your cronjob inside the file 'root'.
echo '
53 * * * * reboot' >> /data/crontab/root
Test without rebooting
Now open any terminal emulator in device and run the following commands..
su -
crond -b -c /data/crontab
Now the crond service will start, to check type pgrep -l crond
or ps | grep crond
Start crond at boot
create a file at /system/etc/init.d with executable permission:
echo '
crond -b -c /data/crontab' > /system/etc/init.d/crond
chmod +x /system/etc/init.d/crond
Example cronjobs
53 * * * * reboot
Will reboot your device on 53rd minute of every hour.
Note:
1. If you modify crontab, remember to restart crond daemon after killing the existing one.
If the crond is not obeying your timezone, you might need to update the tzdata in your device.
Better to test with */1 * * * * to see if it is working.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…