Lengthy sleep command not working in script
If it’s the terminal thing @IrfanLatif wrote, try this:

#!/system/bin/sh
# run a command block in the background, detached from all terminals
/system/bin/sh -T- -c '
    # Wait for boot to complete
    until [ "$(getprop sys.boot_completed)" ]; do
        sleep 300
    done

    while true; do
        (
            new_dir="/storage/emulated/0/temp/AppData/$(date '\''+%Y%m%d-%H%M'\'')"
            mkdir -p "$new_dir"
            cp /data/data/com.example.app/files/*.json "$new_dir"

            echo "$(date '\''+%F %T'\'') | app data backup OK!" &gt;&gt;/storage/emulated/0/su.d.log
        ) &amp;

        sleep 14400 # 4 hours
    done
'


The -T- option tells the shell to daemon()ise, that is, replace stdin, stdout, stderr with /dev/null and double-fork the command into the background. Perhaps this helps.

I don’t have an off-hand idea why this would otherwise not work. Full disclosure: I’m the mksh developer.