EliasKotlyar / Xiaomi-Dafang-Hacks

4.19k stars 1k forks source link

Documentation on Cron / Scheduled Tasks #1807

Open mookman288 opened 2 years ago

mookman288 commented 2 years ago

I have four WyzeCam V2's of various types and firmwares, and I have an issue across all of them where I need to regularly reboot the cameras. Doing this via the GUI daily seems to be fine, but I was wondering if there was a way to automate this process.

In looking at the file structure, I noticed that in /system/sdcard/config/cron there are crontabs and periodic, but I've noticed that nothing I place in the periodic folders seems to execute. Maybe there's a log I'm unaware of?

I was hoping someone who knows how this works could impart some knowledge or documentation.

Thanks!

c--- commented 2 years ago

The system uses BusyBox. Specifically the run-parts command. How are you naming the scripts in the periodic directory?

They can't have an "symbols" in the file name and that includes period so no file extension. The script needs a Shebang at the top too (eg. #!/bin/sh).

famewolf commented 2 years ago

Did you ever get this going? I'm wanting to setup a daily reboot so if the cams hang while I'm away from house at a maximum it would be one day's worth of footage. I wish we could just set an automatic reboot in the gui.

mookman288 commented 2 years ago

I'm not familiar with busybox. I didn't get this working yet, maybe someone else can. Since shutdown isn't available as a command, I was using reboot. I also tried /sbin/reboot in the script, but that didn't work either.

This was the script I was using in /system/sdcard/config/cron/periodic/daily but I am going to try moving it to hourly:

#!/bin/sh

echo `date` > /system/sdcard/reboot.log

reboot

I named the script various things, restart, autorestart, reboot, etc.

I also ran chmod +x reboot.sh in the correct folder.

It works fine if I run it manually, but it doesn't trigger the scripts in those folders.

I did read this: https://superuser.com/a/719493

Maybe it's the fact that it ends in .sh?

kittenarmy commented 2 years ago

I'm having the same issue trying to run scripts. They work when entered over SSH, for example busybox ntpd -d but this doesn't work or even simple curl.

#!/bin/sh
busybox ntpd -d
## tried this too
## /system/sdcard/bin/busybox ntpd -d -N -q

It makes me wonder if busybox needs correct permissions to run as root in run.sh?

morganrallen commented 1 year ago

As per this comment it appear if you remove the .sh extension it should work, did for me at least. https://github.com/EliasKotlyar/Xiaomi-Dafang-Hacks/issues/1462#issuecomment-637045402