📜 ⬆️ ⬇️

Linux - WiFi Starting Script

Recently, the task of making automatic connection of the waffle to the access point has become the stake. WPA encryption algorithm. Without thinking, I sat down to google at least information for writing bashskript. And now in order.

Running waffles


As everyone is well aware, connecting to a network with WPA password encryption in Linux takes place through the wpa_supplicant program. It uses the config that is generated by the wpa_passphrase program and connects the computer to the network declared in this config. So, the tasks that the script should perform:


Script itself


Immediately I ask you not to criticize for the possible curvature of the structure, I am a beginner in bash:
StartWiFi
#!/bin/bash CONFIG=/usr/share/wifi_config if ps ax | grep -v grep | grep wpa_supplicant > /dev/null then echo -e " \E[1;32m********************************************************************************* * * * WiFi already started * * * *********************************************************************************\E[0m "; else if [ -e $CONFIG ] then echo -e " \E[1;33m********************************************************************************* * * * WiFi starting... * * * *********************************************************************************\E[0m " wpa_supplicant -Dwext -iwlan0 -c$CONFIG & > /dev/null sleep 3 dhcpcd wlan0 >> /dev/null echo -e " \E[1;32m********************************************************************************* * * * WiFi starting success! * * * *********************************************************************************\E[0m "; else echo -e " \E[1;31m********************************************************************************* * Config file not exist, use: * * \E[01;32mwpa_passphrase SSID LOGIN PASSWORD >> /usr/share/wifi_config\E[1;31m * * and start this script again. * *********************************************************************************\E[0m "; fi fi 

I used color escape sequences to improve the readability of the output text.
Make the script executable with
 chmod +x /wifi 

and link it to be able to run it without specifying a folder.
 ln -s /wifi /usr/bin/startwifi 

So, the script is ready, it's time to register it in autorun.
')

Autostart


For autorun, I used the /etc/rc.local file, which I just need to add
 startwifi 

And from this point on, the waffle will automatically start when the system starts (of course, the script can also be run with pens)

That's all, thank you for your attention, I will gladly accept all criticism and corrections =)

Source: https://habr.com/ru/post/148689/


All Articles