You are not logged in.

#1 2011-10-22 09:56:29

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Newbies can script! Script to connect to the internet with WPA.

Assuming you have wpa_supplicant set up:

#!/bin/bash
# A simple script to ease your life.
echo First, please type in the name of your wireless adapter "(normally wlan0)".
read INTERFACE
echo Please enter what DHCP client you want to use "(dhcpcd or dhclient)"
echo Not sure? Type dhcpcd.
read CLIENT
echo Putting $INTERFACE up.
sleep 1s                
echo                                  "</--------->"
sleep 1s
ip link set $INTERFACE up                  
echo                                  "<//-------->"
sleep 2s
echo                                  "<///------->"
sleep 1s
echo Getting access via WPA.
sleep 1s
echo                                  "<////------>"
wpa_supplicant -B -Dwext -i $INTERFACE -c /etc/wpa_supplicant.conf
echo                                  "</////----->"
sleep 2s
echo                                  "<//////---->"
sleep 1s
echo Obtaining a address.
if [[ "$CLIENT" == "dhcpcd" ]]
then
dhcpcd $INTERFACE
else
dhclient $INTERFACE
fi
sleep 1s
echo                                  "<///////--->"
sleep 1s
sleep 2s
echo                                  "<////////-->"
sleep 1s
echo                                  "</////////->"
sleep 2s
echo                                  "<//////////>"
ifconfig $INTERFACE
sleep 1s
echo If the ping works, this means the connection is succesful!
ping -c 5 www.google.com
sleep 1s

I know there is room for improvement, but I think that's pretty good for a user that used Arch ONE week and never scripted before.
No, I didn't copy this script from other sites.
So, what can I script next?

Last edited by VOT Productions (2011-10-22 11:33:06)

Offline

#2 2011-10-22 10:01:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: Newbies can script! Script to connect to the internet with WPA.

printf "%s\n" "Please use \[code\] tags when pasting scripts on the boards. Thanks."

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2011-10-22 10:05:01

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Re: Newbies can script! Script to connect to the internet with WPA.

Whoops, I forgot, thanks for reminding me.

Offline

#4 2011-10-22 10:22:33

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Newbies can script! Script to connect to the internet with WPA.

You have a second dhclient call in there, outside the $CLIENT if statement.

Personally, I prefer scripts like this to be non-interactive, apart from a -h/--help type thing to tell me what arguments to provide.

Offline

#5 2011-10-22 10:30:21

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Re: Newbies can script! Script to connect to the internet with WPA.

I'll consider two versions: interactive and arguments.

Edit: Woah, explains why internet kept crashing when using dhcpcd. Fixed it.

Last edited by VOT Productions (2011-10-22 10:31:54)

Offline

#6 2011-10-22 10:45:13

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Newbies can script! Script to connect to the internet with WPA.

After another quick look - you have arbitrarily decided that your dhcp client process will take 14 seconds, and you have no check after that to make sure it was successful. 'iwconfig' at the end shows wireless link info, not ip info.

Offline

#7 2011-10-22 11:29:41

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Re: Newbies can script! Script to connect to the internet with WPA.

WPA Internet CONNECT! 1.1
It has now a ping feature after it's done, IP info, and it takes less time!
See what I meant by newbie?

By the way, it still does time a bit of time. The reason is because I want these extra few seconds for it to connect. Sometimes you might get an IP and not connect instantly.

Last edited by VOT Productions (2011-10-22 11:32:49)

Offline

#8 2011-10-22 13:03:47

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Newbies can script! Script to connect to the internet with WPA.

Your next challenge - put the ping test in a while loop. smile

Offline

#9 2011-10-22 16:45:16

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Re: Newbies can script! Script to connect to the internet with WPA.

Where exactly?
I mean when shall I put it?

Last edited by VOT Productions (2011-10-22 16:47:48)

Offline

#10 2011-10-23 01:12:02

tomk
Forum Fellow
From: Ireland
Registered: 2004-07-21
Posts: 9,839

Re: Newbies can script! Script to connect to the internet with WPA.

Immediately after the $CLIENT if statement, instead of all those sleeps and echos.

Offline

#11 2011-10-23 08:22:13

VOT Productions
Member
Registered: 2011-10-22
Posts: 47

Re: Newbies can script! Script to connect to the internet with WPA.

Ah good idea since you waste 5 seconds.

Another question: Should I Ioop ping while doing what?

Last edited by VOT Productions (2011-10-23 08:28:27)

Offline

Board footer

Powered by FluxBB