shaveax
shaveax

Reputation: 478

how can i created a script with adb shell commands

I have been trying to add a wifi network with these commands inside a script:

adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0

# Get to wpa_cli prompt
adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0

# Add new WiFi network
adb shell add_network

adb shell set_network 0 auth_alg OPEN 
adb shell set_network 0 key_mgmt WPA-PSK 
adb shell set_network 0 ssid "Password" 
adb shell set_network 0 proto RSN
adb shell set_network 0 mode 0 
adb shell set_network 0 psk "Mynetwork name"

# Connect to it
adb shell select_network 0 
adb shell enable_network 0
adb shell reassociate 

# Check the status
adb shell status

but after the first command the terminal stays always in adb shell prompt and the other commands are not executed

Upvotes: 1

Views: 1664

Answers (1)

Alex P.
Alex P.

Reputation: 31676

WPACLI="adb shell wpa_cli -p /data/misc/wifi/sockets/ -i wlan0"

# Add new WiFi network
NETWORK=$($WPACLI add_network)

$WPACLI set_network $NETWORK auth_alg OPEN 
$WPACLI set_network $NETWORK key_mgmt WPA-PSK 
$WPACLI set_network $NETWORK ssid "Password" 
$WPACLI set_network $NETWORK proto RSN
$WPACLI set_network $NETWORK mode 0 
$WPACLI set_network $NETWORK psk "Mynetwork name"

# Connect to it
$WPACLI select_network $NETWORK
$WPACLI enable_network $NETWORK
$WPACLI reassociate 

# Check the status
$WPACLI status

Upvotes: 1

Related Questions