FreeBSD rc.subr wireless script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting FreeBSD rc.subr wireless script
# 1  
Old 06-16-2012
FreeBSD rc.subr wireless script

Hi,

This is my first thread on Unix forums, so be gentle.Smilie

I'm trying to write a simple start/stop script for my wireless networking adapter, under FreeBSD, using the rc.subr framework.

Code:
 
#!/bin/sh

# PROVIDE Wireless
# KEYWORDS shutdown

. /etc/rc.subr

name="wireless"
start_cmd="${name}_start"
stop_cmd="${name}_stop"


wireless_start()
{

#Check whether wlan0 already exists

        for faces in `ifconfig -lu`
do
        if [ "$faces" != "wlan0" ]
then

//Create the device
ifconfig wlan0 create wlandev iwn0
        fi
done

#Add an ip address
ifconfig wlan0 inet 192.168.2.12 netmask 255.255.255.0

route add -net default 192.168.2.45

wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf &
}

wireless_stop()
{
        ifconfig wlan0 down 2> /dev/null
        route delete -net default 192.168.2.45
        ifconfig wlan0 destroy wlandev iwn0 2> /dev/null


}
load_rc_config $name
run_rc_command "$1"

Is this ok? Is there a better way ?

Regards Regexp
# 2  
Old 06-17-2012
First off, let me congratulate you: this is by far the best first posting i have read here for ages. You even seem to understand how to use CODE-tags, which will earn you the eternal respect and heartfelt thankfulness of the complete moderation team.

Quote:
Originally Posted by regexp
Is this ok? Is there a better way ?
This is OK. In fact, start-/stop-scripts have been written this way for a long time.

Just as a suggestion, you might want to add a "restart" function, which simply consists of a call to "stop()" first and then a call to "start()".

Another suggestion: do you really want to hard-code the IP address into a rc-script? You might want to make the script more generic by obtaining the IP-address in its own script. This would either read it from some configuration file or get it via DHCP, bootp or the like.

I hope this helps.

bakunin
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Changing script to work with freeBSD

hi all, i have made my machine a freeBSD machine instead of a centos machine and my script doesnt work anymore and i was wondering if anyone can help me into why, i thought the commands are the same, here it is - #!/bin/bash source=/vol/cha-work/_ARCHIVE/to_be_archived/audio... (9 Replies)
Discussion started by: robertkwild
9 Replies

2. BSD

An installation script on freeBSD

Hello So i got my hands on some freebsd iso, installed it in a qcow2 image and installled git and bash. So far, so good. Git repositry retireved install script executed files got copied files have exec flag files are in $PATH / found by which / bash-completion works But still,... (3 Replies)
Discussion started by: sea
3 Replies

3. UNIX for Dummies Questions & Answers

'awk' help for script to clean out wireless.

I've been working on a script to clean out the wireless connections on my MAC. I know the terminal command to do this (that part is not rocket science ;) ) So I thought I would have a go at automating this but I'm having trouble with the 'awk' command & the correct context. My code is := ... (7 Replies)
Discussion started by: Lord Lien
7 Replies

4. Shell Programming and Scripting

FreeBSD new user login script

I am a beginner programmer and would like to know where to start to modify the login process so that a user can login as username new password new and have it prompt user for username and password and nothing else and then create said user account on the system so they can ssh back in and login... (9 Replies)
Discussion started by: deshi
9 Replies

5. Linux

how to configure wireless now ?

Hi, I've installed wireless card and I didn't receive any error in the installation process. Now I want to use it but I can't make internet to work. if I check my card with iwconfig I get the following message wlan0 IEEE 802.11g ESSID:"Alice-34376718" Mode:Managed ... (2 Replies)
Discussion started by: aneuryzma
2 Replies

6. Programming

Application crashes in FreeBSD 7.1 while working ok in FreeBSD 6.3

Hello there, My mulithreaded application (which is too large to represent the source code here) is crashing after installing FreeBSD 7.1-RELEASE/amd64. It worked properly on others machines (Dual Cores with 4GB of RAM - FreeBSD 6.2-RELEASE/i386). The current machine has 2x Core 2 Duo... (1 Reply)
Discussion started by: Seenquev
1 Replies

7. Shell Programming and Scripting

My Wireless Script Wont Work.....anyone??

ive been trying to write a simple (at least i thought it was) script to launch my wireless usb under ubuntu with kde. im using nano. when i run it from a terminal it works fine, but it just wont run from the script. there is a caveat, but first heres the script. ... (7 Replies)
Discussion started by: braze
7 Replies

8. BSD

FreeBSD Wireless - Can do WPA but not WEP or even open

Hello, I am using FreeBSD on my laptop (R60) and currently it is working great, however, I am having trouble connecting to open or WEP secured networks. I have read the FreeBSD handbook regarding this many times. That is how I found out how to connect to WPA networks. If anyone could post a... (4 Replies)
Discussion started by: kpedersen
4 Replies

9. BSD

OpenBSD and wireless

I've just installed OpenBSD on my laptop (IBM Thinkpad T42) and since this is my first time with wireless networking in OpenBSD I'm a bit lost. What I would like to do is connect to a wireless network using WEP or WPA. Where do I place the key and essid? (3 Replies)
Discussion started by: Timmy66
3 Replies

10. HP-UX

Wireless

Can someone please point me in the correct direction for setting up a wireless card using HP-UX 11iV1? I know its different depending on the type of card I have, but im looking for a direction. Thanks! (0 Replies)
Discussion started by: nickwinnie
0 Replies
Login or Register to Ask a Question