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
You will likely need to set your TimeZone and add a root user. Adding a root user can be done like this:
echo "root:x:0:0::/system/etc/crontabs:/system/bin/sh" > /system/etc/passwd
Getting the right TimeZone string is odd. Set the TZ environment variable to the timezone string and make sure crond gets it. I have it under control of a GUI environment, and use the following for getting the TimeZone (may not be correct as I've not tested it on other timezones yet).
public static String findTZS() {
String date = ZooGate.readShellCommand("date");
String[] elements = date.split(" ");
String label = elements[4];
TimeZone tz = Calendar.getInstance().getTimeZone();
boolean dlt = tz.useDaylightTime();
int offset = tz.getDSTSavings()/600000;
DateFormatSymbols dfs = DateFormatSymbols.getInstance();
String[][] z = dfs.getZoneStrings();
for (String[] za: z) {
if (dlt) {
if (za[4].equals(label)) {
return za[2] + offset + za[4];
} else if (za[2].equals(label)) {
return za[2] + offset + za[4];
}
}
}
return "UTC";
}
Also be sure your crontab is named for the user (root) and also owned by that user. If you set the crontab on your internal storage so that you can edit it with Android text editors, you can make it a symlink to /data/media/0. I use /system/etc/crontabs/root -> /data/media/0/Cron/master
You use /data/media and /storage or /sdcard because the latter is a FUSE filesystem that hides the underlying Unix file system permissions and ownership, so you need to set the ownership on the real filesystem in /data.
If you have an older Android that uses Fat or YAFFS or whatever for the internal storage then you might have to keep your crontabs in /system
Beware that cron doesn't always run on time under Android since it likes to oversleep.