I have a really simple shell script, that just adds a route to my internal development machine. This is useful, as that machine has some LXC containers inside, so I can reach all my containers from my cell phone (to test websites from mobile browser, or Asterisk SIP accounts from CSipSimple)

su -c "ip route add via dev wlan0"

To use this rule, I've created a new Local connection on ConnectBot, with the script name as login command. This works great.

However, I'm too lazy. I just want to know if there is some way to apply this script, as soon as I connect to my home WiFi automatically. Maybe something to execute a script on every network change, as I could check from same script if I'm connected to my home WiFi using dumpsys and some grep magic.

  • 1
    Have you looked at Tasker? That's generally the go-to app for triggered automation tasks on Android. – Matthew Read May 7 '15 at 22:46
  • Thanks @Matthew, I've used AutomateIt and Shell Plugin, and works great! That solve my problem. However, maybe someone could explain if Android triggers some script at network changes, like other Linux variants do with ifup-ifdown files – Eduar May 8 '15 at 15:57
  • I wouldn't be surprised if there was, but I'm not familiar with that sadly. – Matthew Read May 8 '15 at 17:30
  • I'm still looking for such a tool, since I just can't accept to install an 18MB monster like AutomateIt just to run a one-liner script. – Stefan Oct 13 '15 at 20:47

Matthew already pointed to for this task (uh) – an app I already use for years. So let me add the steps to achieve this. Obviously, a pre-condition is the device is rooted – but the su command in the question tells me it is. So here we go:

  • Condition: State › Net › WiFi Connected
    As parameter, include the SSID of your WiFi network, so it doesn't fire on alien networks :)
  • Task: Script › Run Shell
    Here you add the name of the script to run (full path), preceded by an exclamation mark (to indicate it must be run as root)

This should do it. Not tested myself, as I have no routes to add :)

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.