VectorLinux
October 20, 2014, 08:58:51 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Visit our home page for VL info. To search the old message board go to http://vectorlinux.com/forum1. The first VL forum is temporarily offline until we can find a host for it. Thanks for your patience.
 
Now powered by KnowledgeDex.
   Home   Help Search Login Register  
Please support VectorLinux!
Pages: [1]
  Print  
Author Topic: How to call external script for wireless networking from startup?  (Read 2577 times)
Verlager
Member
*
Posts: 34


« on: June 25, 2007, 04:08:13 pm »

I wrote a script called "wireless.sh" and I want to call it from /etc/rc.d/rc.local.

What is the command (yes, I tried google) to call an external script from this start-up  script?

If this this startup script calls this external "wireless.sh" script, and a wired eth0 is present and functioning, which interface will be used? I think the hardwired one will be used. I don't want to put these commands in /etc/rc.d/rc.local. And thanks for the excellent how-to on wireless networking, without which, I never could have done this.

OK, here it the script; comments are welcome, and please feel free to use it.

#!/bin/bash
# wireless.sh
# establishes ath0 wireless connection to the Linksys Router, using WEP or WPA encryption
# Change all "ath0" to whatever your interface may be.

# set the router ESSID
iwconfig ath0 essid "linksys"

# not sure ....
iwconfig ath0 mode Managed

# Channel = Auto or the channel #
iwconfig ath0 channel 6

# Access point
iwconfig ath0 ap any

# set the WEP encryption key (edit the XXXXXXXXXX)
iwconfig ath0 key XXXXXXXXXX

# Connect with WPA encryption
wpa_supplicant -B -Dwext -iath0 -c/etc/wpa_supplicant.conf

#start the network using dhcp
dhcpcd -t 25 -d ath0
Logged

Fear believes; courage doubts. Fear falls upon the earth and prays; courage stands erect and thinks. Fear retreats; courage advances. Fear is barbarism; courage is civilization. Fear believes in witchcraft, in devils and in ghosts. Fear is religion, courage is science. —Robert Ingersoll
easuter
Global Moderator
Vectorian
*****
Posts: 2160



« Reply #1 on: June 25, 2007, 04:54:44 pm »

Well, you can put it in /usr/sbin for starters (have to be root for that) Smiley.

After saving it in /usr/sbin, make the script executable:

Code:
chmod +x /usr/sbin/wireless.sh

Then, to call it from rc.local, edit /etc/rc.d/rc.local and add /usr/sbin/wireless.sh right at the end of the file.
When you boot up again, your script will be run.
Logged

Verlager
Member
*
Posts: 34


« Reply #2 on: June 25, 2007, 07:38:15 pm »

worked like a charm!

Is there is a way to conditionally branch to the wireless.sh script if the eth0 interface isn't accessing the LAN at boot time?
« Last Edit: June 25, 2007, 08:06:09 pm by Verlager » Logged

Fear believes; courage doubts. Fear falls upon the earth and prays; courage stands erect and thinks. Fear retreats; courage advances. Fear is barbarism; courage is civilization. Fear believes in witchcraft, in devils and in ghosts. Fear is religion, courage is science. —Robert Ingersoll
saulgoode
Vectorite
***
Posts: 340



« Reply #3 on: June 25, 2007, 08:29:11 pm »

Code:
if $(/sbin/ifconfig eth0 2&>1 >/dev/null); then echo eth0 exists; else echo eth0 does not exist; fi

The above script line will print a message based upon whether or not eth0 exists. To actually test whether it is connected, you will need a command other than ifconfig (perhaps pinging your router?). Modify the echo statements to call the appropriate scripts.

The "2&>1 >/dev/null" in the command effectively instructs it to run without producing any output. The "2&>1" redirects error messages to the program's standard output and the ">/dev/null" redirects that to the bit bucket (i.e., "nowhere"). The only thing of interest from the ifconfig command is its return value, which is tested by the "if" statement (a return of non-zero means the command failed).

I would not recommend placing your script in "/usr/sbin" because there is no guarantee that /usr will be mounted at the time your script is executed. It is not unreasonable for the bootup sequence to wish to access the network before mounting "extra" partitions (the only partition guaranteed to be mounted at boot time is the root partition, "/"). Your script should be placed in either "/sbin" or in "/etc/rc.d/" (my preference would be the latter, with a script named "rc.linksys-WPA" or somesuch).

Logged

A complex system that works is invariably found to have evolved from a simple system that works.
Verlager
Member
*
Posts: 34


« Reply #4 on: July 23, 2007, 10:23:58 am »


I want to edit /etc/rc.d/rc.local and include a line: wireless.sh ath0
When I tried this with $1, it worked only at the command line.
Is there a way to make all instances of the string "ath0" in the following shell script into a replaceable parameter called from another script?

I wrote a script called "wireless.sh" and I want to call it from /etc/rc.d/rc.local.

What is the command (yes, I tried google) to call an external script from this start-up  script?

If this this startup script calls this external "wireless.sh" script, and a wired eth0 is present and functioning, which interface will be used? I think the hardwired one will be used. I don't want to put these commands in /etc/rc.d/rc.local. And thanks for the excellent how-to on wireless networking, without which, I never could have done this.

OK, here it the script; comments are welcome, and please feel free to use it.

#!/bin/bash
# wireless.sh
# establishes ath0 wireless connection to the Linksys Router, using WEP or WPA encryption
# Change all "ath0" to whatever your interface may be.

# set the router ESSID
iwconfig ath0 essid "linksys"

# not sure ....
iwconfig ath0 mode Managed

# Channel = Auto or the channel #
iwconfig ath0 channel 6

# Access point
iwconfig ath0 ap any

# set the WEP encryption key (edit the XXXXXXXXXX)
iwconfig ath0 key XXXXXXXXXX

# Connect with WPA encryption
wpa_supplicant -B -Dwext -iath0 -c/etc/wpa_supplicant.conf

#start the network using dhcp
dhcpcd -t 25 -d ath0

Logged

Fear believes; courage doubts. Fear falls upon the earth and prays; courage stands erect and thinks. Fear retreats; courage advances. Fear is barbarism; courage is civilization. Fear believes in witchcraft, in devils and in ghosts. Fear is religion, courage is science. —Robert Ingersoll
bigpaws
Vectorian
****
Posts: 1856


« Reply #5 on: July 23, 2007, 03:15:53 pm »

I think I understand what you want.

Move the script wireless.sh ath0 (rename to ath0.sh ir wiresless_ath0.sh) easy to
see what you did to /etc/rc.d.

Make the file executable chmod -x /etc/rc.d/ath0.sh

Then in /etc/rc.d/rc.local at the bottom write ath0.sh and the script will be executed on boot.

Now if you wish to call the script later use /etc/rc.d/ath0.sh. That should do it.

HTH

Bigpaws
Logged
Verlager
Member
*
Posts: 34


« Reply #6 on: July 23, 2007, 05:56:16 pm »

Echh... I think I lost track. What I'm trying to do is make my silly script universally available to users who have some some other wireless card than ath0. User may have wlan1 or ath1, or some such. Ideally, what the user would do is install the wireless card, poll iwconfig, find out what his wireless NIC interface is and then edit /etc/rc.d/rc.local with a line: wireless.sh {ath0/ath1/wlan0/...}

Then I would edit the wireless.sh to include $1 for the replaceable parameter:

Code:
iwconfig ath0 mode Managed

becomes:

iwconfig $1 mode Managed

#or something

I would like the user to be able to include a line calling this script in a start-up file with a replaceable parameter, or execute the script manually from the command line. What is the scripting language that Linux uses that has colors and prompts and all that good stuff? I think I like to toy around with that, if I could.
Logged

Fear believes; courage doubts. Fear falls upon the earth and prays; courage stands erect and thinks. Fear retreats; courage advances. Fear is barbarism; courage is civilization. Fear believes in witchcraft, in devils and in ghosts. Fear is religion, courage is science. —Robert Ingersoll
exeterdad
Packager
Vectorian
****
Posts: 2046



« Reply #7 on: July 23, 2007, 06:14:20 pm »

That would be bash. It can have pretty colors.  It can prompt.  You can use it with zenity for a gui-like interface for the users.
« Last Edit: July 23, 2007, 06:17:24 pm by exeterdad » Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!