own script android 10

Search This thread

Tubeczka

Member
Sep 23, 2022
10
0
Hello,

I have android 10, Samsung a7, I have root by custom firmware + magisk.
i have script in:
Code:
/data/adb/service.d
service.d have:
Code:
drwxr-xr-x  2 root   root   4.0K 2022-09-25 14:13 service.d
inside I have file shoutdown:
Code:
-rwxr-xr-x 1 root shell  411 2022-09-25 15:35 shoutdown

script:
Bash:
#!/system/bin/sh

sleep 100

is_charging()
{
    [ $(cat /sys/class/power_supply/battery/status) = Charging ] || [ $(cat /sys/class/power_supply/battery/status) = Full ] || return 1
}

# keep waiting
while is_charging; do sleep 1; done

# charger is disconnected, countdown
sleep 300

# again start waiting if charger is connected
is_charging && exec $(realpath $0)

# else, shutdown
/system/bin/reboot -p charger_disconnected ||
/system/bin/setprop sys.powerctl shutdown,charger_disconnected

Didn't work... I have the same code in another phone with android 5.0 (another place in android -> init.d) and this script works.
I'm programmer Js/node/python, I don't know android and language bash. I'm trying to set up my phone for self-use (auto turn on/turn off when phone is charging/isn't charging and auto lanuch some applications after start system)

Can someone please help?
 

Oswald Boelcke

Senior Moderator / Moderator Committee
Staff member
Can someone please help?
Hello and good afternoon, @Tubeczka

Welcome to XDA. I hope you'll always find and get the support you require.

However, prior to your next posting please read the guidances that are stuck on top of every forum like
and the others. I've moved the thread to Android Q&A.

Thanks for your cooperation!
Regards
Oswald Boelcke
Senior Moderator
 

bnsmb

Senior Member
Aug 22, 2017
176
88
Frankfurt
Hello,

I have android 10, Samsung a7, I have root by custom firmware + magisk.
i have script in:
Code:
/data/adb/service.d
service.d have:
Code:
drwxr-xr-x  2 root   root   4.0K 2022-09-25 14:13 service.d
inside I have file shoutdown:
Code:
-rwxr-xr-x 1 root shell  411 2022-09-25 15:35 shoutdown

script:
Bash:
#!/system/bin/sh

sleep 100

is_charging()
{
    [ $(cat /sys/class/power_supply/battery/status) = Charging ] || [ $(cat /sys/class/power_supply/battery/status) = Full ] || return 1
}

# keep waiting
while is_charging; do sleep 1; done

# charger is disconnected, countdown
sleep 300

# again start waiting if charger is connected
is_charging && exec $(realpath $0)

# else, shutdown
/system/bin/reboot -p charger_disconnected ||
/system/bin/setprop sys.powerctl shutdown,charger_disconnected

Didn't work... I have the same code in another phone with android 5.0 (another place in android -> init.d) and this script works.
I'm programmer Js/node/python, I don't know android and language bash. I'm trying to set up my phone for self-use (auto turn on/turn off when phone is charging/isn't charging and auto lanuch some applications after start system)

Can someone please help?
Hi


does the script work if executed in a (root) shell?

paste the contents of the file

/cache/magisk.log

and the output of the commands (executed as user root):

sh -x -n /data/adb/service.d/shoutdown

ls -l /data/adb /data/adb/service.d/

magisk -V

magisk -v


regards

Bernd
 
  • Like
Reactions: Tubeczka

Tubeczka

Member
Sep 23, 2022
10
0
I tried:
Code:
a7y18lte:/ $ /system/bin/setprop sys.powerctl shutdown,charger_disconnected
a7y18lte:/ $
C:\Program Files (x86)\Minimal ADB and Fastboot>
The system has shout down

Code:
a7y18lte:/cache # cat magisk.log
09-26 09:12:13.700  3650  3650 I : Magisk 25.2(25200) daemon started
09-26 09:12:13.701  3650  3650 I : * Device API level: 29
09-26 09:12:13.713  3650  3652 I : ** post-fs-data mode running
09-26 09:12:13.713  3650  3652 I : * Mounting mirrors
09-26 09:12:13.714  3650  3652 I : mount: /sbin/.magisk/mirror/vendor
09-26 09:12:13.714  3650  3652 I : link: /sbin/.magisk/mirror/cache
09-26 09:12:13.714  3650  3652 I : mount: /sbin/.magisk/mirror/data
09-26 09:12:13.715  3650  3652 I : link: /sbin/.magisk/mirror/system
09-26 09:12:13.715  3650  3652 I : mount: /sbin/.magisk/mirror/system_root
09-26 09:12:13.717  3650  3652 I : link: /sbin/.magisk/mirror/product
09-26 09:12:13.768  3650  3652 I : * Initializing Magisk environment
09-26 09:12:13.886  3650  3652 I : * Running post-fs-data.d scripts
09-26 09:12:13.891  3650  3652 I : * Running module post-fs-data scripts
09-26 09:12:13.891  3650  3652 I : * Loading modules
09-26 11:12:14.870  3650  3652 I : ** late_start service mode running
09-26 11:12:14.871  3650  3652 I : * Running service.d scripts
09-26 11:12:14.939  3650  3652 I : service.d: exec [shoutdown]
09-26 11:12:14.959  3650  3652 I : * Running module service scripts
09-26 11:12:32.299  3650  3652 I : ** boot-complete triggered

Code:
a7y18lte:/ # sh -x -n /data/adb/service.d/shoutdown
a7y18lte:/ # exit
a7y18lte:/ $ sh -x -n /data/adb/service.d/shoutdown
sh: /data/adb/service.d/shoutdown: Permission denied

Code:
a7y18lte:/ # ls -l /data/adb /data/adb/service.d
/data/adb:
total 56
drwxr-xr-x 4 root root  4096 2022-09-25 13:50 magisk
-rw------- 1 root root 40960 2022-09-25 14:05 magisk.db
drwxr-xr-x 2 root root  4096 2022-09-25 13:50 modules
drwxr-xr-x 2 root root  4096 2022-09-26 10:58 post-fs-data.d
drwxr-xr-x 2 root root  4096 2022-09-26 10:58 service.d

/data/adb/service.d:
total 4
-rwxr-xr-x 1 root shell 411 2022-09-25 15:35 shoutdown

Code:
a7y18lte:/ # magisk -V
25200
a7y18lte:/ # magisk -v
25.2:MAGISK:R

Service.d execute when system is running? I need turn on phone after plug in charger, Can I do it?

thank you,
regards
 

bnsmb

Senior Member
Aug 22, 2017
176
88
Frankfurt
Hi

the config looks fine and Magisk executed your script

09-26 11:12:14.871 3650 3652 I : * Running service.d scripts 09-26 11:12:14.939 3650 3652 I : service.d: exec [shoutdown]

Please add some debug code and try again - add these commands and the very beginning of the script:

Code:
exec 1>>/cache/shoutdown.log 2>&1
echo
echo "------------------------------------------------------------"
echo "+++ $0 started at $( date ) "
echo
set -x

When done paste the output of the file /cache/shoutdown.log

I need turn on phone after plug in charger, Can I do it?

I do not understand that question

regards

Bernd
 

Tubeczka

Member
Sep 23, 2022
10
0
Hello,

Code:
a7y18lte:/ # cat cache/shoutdown.log

------------------------------------------------------------
+++ /system/bin/sh started at Mon Sep 26 20:17:20 CEST 2022

+ sleep 100
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1

this is multiply
Code:
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1

Seem code is execute, but my code is not correctly?

I do not understand that question

My phone always will be turn off, when I will start charging phone, phone should turn on, when I plug off cable charge, phone should turn off. Of course with sleep to delay actions.

Thank you for help.
 

bnsmb

Senior Member
Aug 22, 2017
176
88
Frankfurt
Hello,

Code:
a7y18lte:/ # cat cache/shoutdown.log

------------------------------------------------------------
+++ /system/bin/sh started at Mon Sep 26 20:17:20 CEST 2022

+ sleep 100
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1

this is multiply
Code:
+ is_charging
+ '[' Full '=' Charging ]
+ '[' Full '=' Full ]
+ sleep 1

Seem code is execute, but my code is not correctly?



My phone always will be turn off, when I will start charging phone, phone should turn on, when I plug off cable charge, phone should turn off. Of course with sleep to delay actions.

Thank you for help.


HI

Seem code is execute,

yes

but my code is not correctly?

depends on what you want to achieve wit the script

regards

Bernd
 

Tubeczka

Member
Sep 23, 2022
10
0
depends on what you want to achieve wit the script
On another phone the same code doing exactly what I want (Android 5.0 and root by KingRoot, not magisk). After plug on charge cable to phone, system is start, and after plug off charge cable system is shut down.

I don't know why here didn't work?
Maybe you know better solution to solve my problem?
 

Tubeczka

Member
Sep 23, 2022
10
0
I tried this, and it didn't work too:

Bash:
#!/system/bin/sh

sleep 100

/system/bin/reboot -p charger_disconnected ||
/system/bin/setprop sys.powerctl shutdown,charger_disconnected
 

bnsmb

Senior Member
Aug 22, 2017
176
88
Frankfurt
On another phone the same code doing exactly what I want (Android 5.0 and root by KingRoot, not magisk). After plug on charge cable to phone, system is start, and after plug off charge cable system is shut down.

I don't know why here didn't work?
Maybe you know better solution to solve my problem?
Hi

Maybe you know better solution to solve my problem?

I don't know how to do that

regards

Bernd
 

Tubeczka

Member
Sep 23, 2022
10
0
Ok thank you, maybe someone else can help me,

I try and nothing. My script print echo (begin the script), but later after sleep my script don't execute. If I execute the same line in direct adb shell - it working.

Second question: which files is running when my phone is off? I mean service.d is execute by magisk? But I need running script when my phone is off too, to detect charger and phone will wake up (turn on).
 

bnsmb

Senior Member
Aug 22, 2017
176
88
Frankfurt
Ok thank you, maybe someone else can help me,

I try and nothing. My script print echo (begin the script), but later after sleep my script don't execute. If I execute the same line in direct adb shell - it working.

Second question: which files is running when my phone is off? I mean service.d is execute by magisk? But I need running script when my phone is off too, to detect charger and phone will wake up (turn on).

>>Second question: which files is running when my phone is off?

I assume you want to run a script while shutting down the phone -- if yes see here

How to run a script at shtudown

regards

Bernd
 

Tubeczka

Member
Sep 23, 2022
10
0
Thanks,
I change script, when charger is off, my phone will turn on plane mode, so I have script file in:
/data/adb/service.d/my_file
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Hello,

    I have android 10, Samsung a7, I have root by custom firmware + magisk.
    i have script in:
    Code:
    /data/adb/service.d
    service.d have:
    Code:
    drwxr-xr-x  2 root   root   4.0K 2022-09-25 14:13 service.d
    inside I have file shoutdown:
    Code:
    -rwxr-xr-x 1 root shell  411 2022-09-25 15:35 shoutdown

    script:
    Bash:
    #!/system/bin/sh
    
    sleep 100
    
    is_charging()
    {
        [ $(cat /sys/class/power_supply/battery/status) = Charging ] || [ $(cat /sys/class/power_supply/battery/status) = Full ] || return 1
    }
    
    # keep waiting
    while is_charging; do sleep 1; done
    
    # charger is disconnected, countdown
    sleep 300
    
    # again start waiting if charger is connected
    is_charging && exec $(realpath $0)
    
    # else, shutdown
    /system/bin/reboot -p charger_disconnected ||
    /system/bin/setprop sys.powerctl shutdown,charger_disconnected

    Didn't work... I have the same code in another phone with android 5.0 (another place in android -> init.d) and this script works.
    I'm programmer Js/node/python, I don't know android and language bash. I'm trying to set up my phone for self-use (auto turn on/turn off when phone is charging/isn't charging and auto lanuch some applications after start system)

    Can someone please help?
    Hi


    does the script work if executed in a (root) shell?

    paste the contents of the file

    /cache/magisk.log

    and the output of the commands (executed as user root):

    sh -x -n /data/adb/service.d/shoutdown

    ls -l /data/adb /data/adb/service.d/

    magisk -V

    magisk -v


    regards

    Bernd