Sample Header Ad - 728x90

How to run a script in background from adb shell?

3 votes
1 answer
11997 views
I have a problem with USB tethering on my rooted Nougat phone (LineageOS). After some time phone stops USB tethering. To fix that I run the following script like this: adb shell su nohup sh tether.sh & exit exit tether.sh #!/system/bin/sh service list while true; do if ! pidof -s dnsmasq > /dev/null then echo -n "Connectivity lost at " date -u +%FT%TZ echo "Waiting 3 seconds..." sleep 3 echo "Calling ConnectivityManager.setUsbTethering(false)" service call connectivity 33 i32 0 2>&1 sleep 3 echo "Calling ConnectivityManager.setUsbTethering(true)" service call connectivity 33 i32 1 2>&1 echo "Waiting 3 seconds..." fi sleep 3 done Problem: If I use nohup my call to service call connectivity fails with service not found. And I put service list on top of the script which returns Found 0 services:. However the same commands work when ran directly from adb shell; su. Why service call doesn't work inside this background script? Does it need the same tty to work?
Asked by Nazar554 (188 rep)
Aug 27, 2019, 08:33 PM
Last activity: Jun 17, 2025, 06:35 PM