4

I want to write a bash script (similar to Linux) to run a cron job every 10 hour. The task is fairly simple, e.g. deleting files from cache folder.

According to this topic, I installed busybox and terminal emulator and phone has already been rooted. Here is what I did:

su -
echo "*/5 * * * * root reboot" >> /data/crontab/root
crond -b -c /data/cronjob

Note that for the test, I set the phone to reboot every 5 minutes to see if crond is properly working.

Problem is, it doesn't work! Any idea for that?

0

Requirements

  1. Root access
  2. Busybox : for 'crond' service
  3. /system/etc/init.d folder to start 'crond' service at boot

Creating cronjob Create the cronjob file in directory /data/crontab/ with filename root. Write your cronjob inside the file 'root'. Set executable permissions for the file 'root'

Test without rebooting Now open any terminal emulator in device and run the following commands..

su -
crond -b -c /data/cronjob

Now the crond service will start, to check type...

top | grep crond

Start crond at boot

  1. mount system partition in read write :

    su -

    mount -o remount,rw /system

  2. Create a file 99my_daemon at /system/etc/init.d with executable permission and enter the following lines

    crond -b -c /data/crond

  3. Close writing the /system partition

    mount -o remount,rw /system

  4. And reboot

Example of cron filename root

*/15 * * * * reboot

Will reboot your device every 15 minutes from o'clock.

| improve this answer | |
  • To disable read write mode need to enter mount -o remount,ro /system command – QkiZ Sep 4 '19 at 6:21
  • This solution will work only if there will be no OOM situation. If OOM killer starts working because system doesn't have free memory crond may be killed. – QkiZ Sep 4 '19 at 6:23

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.