How can I run a script on boot?

  • I'm accustomed to running scripts on boot in Linux, but I'm not sure how to do this in Android. I'd like to start my SSH daemon on start, so I'll always be able to connect. How can I run an arbitrary script on Android boot? It'd be preferable to do this outside of Dalvik.

  • While looking around my Android filesystem, I found that it did, in fact have a /etc/init.d/ directory. After peeking around in there, I found /etc/init.d/20userinit with the following lines:

    if [ -e /data/local/ ];
        log -p -i -t userinit "Executing /data/local/";
        busybux chmod +x /data/local/;
        logwrapper /system/bin/sh /data/local/;
        setprop 1;

    This being, of course, exactly what I needed, I wrote the following script on my computer then pushed it to my device:

    dropbear -s -g 

    (pushed to device via scp phone:/data/local/, mind you :] )

    Rebooted the device, then ran ps | grep "[d]ropbear", and sure enough, it's running. Coolness!

    Comments are not for extended discussion; this conversation has been moved to chat.

License under CC-BY-SA with attribution

Content dated before 6/26/2020 9:53 AM