Sample Header Ad - 728x90

Lengthy sleep command not working in script

1 vote
3 answers
2387 views
I've written a su.d script to periodically (every 4 hours) back up data from an app using a looped sleep command: #!/system/bin/sh ( # 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!" >> /storage/emulated/0/su.d.log ) & sleep 14400 # 4 hours done ) & In practice, the script backs up the data only after boot—not every 4 hours. However, if I enter a remote shell via adb and leave it alone, then the data does get backed up every 4 hours. How can I force the periodic backup without being permanently connected to a PC? (And why isn't it working as expected?) --- ### EDITS ### 1. @Irfan Latif's comment gave me the idea of trying a different interpreter (busybox ash - #!/system/xbin/sh), but the result was the same. I'll try @mirabilos's daemonise suggestion (sh -T- -c '...') next. 2. Tried @mirabilos's daemonise suggestion with the same result: backs up data only after boot. 3. Tried nohup: nohup /system/bin/sh -T- -c '...' >/dev/null 2>&1 & Same result.
Asked by andronoid (41 rep)
Feb 17, 2019, 03:01 PM
Last activity: May 5, 2020, 11:33 AM