How to use crontab in Android?

后端 未结 4 801
你的背包
你的背包 2020-12-13 06:59

I can\'t find answer to my question: Is it possible to run crontab to reboot Android using busybox (or other means)

Tried to run crontab, a

4条回答
  •  借酒劲吻你
    2020-12-13 07:42

    Requirements

    1. Root access: for superuser commads like reboot, or init.d config. Crond can still run under normal user privs.

    2. Busybox: for 'crond' service

    3. (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.

    1. If the crond is not obeying your timezone, you might need to update the tzdata in your device.

    2. Better to test with */1 * * * * to see if it is working.

提交回复
热议问题