-6

I have to add multiple AP and passwords to multiple Linux machines and need to automate that. Recently I've write a bash script to write configs to files in /etc/NetworkManager/system-connections/ like the files that were generated by the system. But without success.

EXAMPLE:

I have a file AP.txt with MAC addresses, SSID and password:

xx:xx:xx:xx:xx:x1;ssid1;pass1
xx:xx:xx:xx:xx:x2;ssid2;pass2
xx:xx:xx:xx:xx:x3;ssid3;pass3
xx:xx:xx:xx:xx:x4;ssid4;pass4

and multiple machines:

pc1
pc2
pc3
...

I would like to make a script to add those AP to my computers automaticaly, so that every machine can connect automatically to the nearest AP.

0

Assuming you have root ssh keys setup and locally generated templates, stat with this;

for HOST in $HOSTS ; do
    scp wifi-templates/* $HOST:/etc/NetworkManager/system-connections/
    ssh $HOST 'U=$(ls -1 /home/ | head -n 1); perl -pi -e "s/(permissions=user:)you(:;)/$1'$U'$2/g" /etc/NetworkManager/system-connections/*'
done

Templates;

while read L ; do
    SSID=$(echo $L | cut -d ";" -f 1)
       N=$(echo $L | cut -d ";" -f 2)
    PASS=$(echo $L | cut -d ";" -f 3)
    cp template $N
    perl -pe 's/SSID/'$SSID'/g;s/PASS/'$PASS'/g' $N
done < AP.txt

*This code is for demonstration only (untested and may require tweaking for it to work) Please read the man page of each command before use;

  • Thank you for your help, but I need to do the template, need help with that. I tried to manualy insert a template to /etc/NetworkManager/system-connections/ but when near an AP that I added it doesnt connect to them. – molotow Mar 27 '18 at 16:06

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.