You are not logged in.
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
printf "%s\n" "Please use \[code\] tags when pasting scripts on the boards. Thanks."
Offline
Whoops, I forgot, thanks for reminding me.
Offline
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
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
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
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
Your next challenge - put the ping test in a while loop.
Offline
Where exactly?
I mean when shall I put it?
Last edited by VOT Productions (2011-10-22 16:47:48)
Offline
Immediately after the $CLIENT if statement, instead of all those sleeps and echos.
Offline
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