mpalomer
Posts: 26
Joined: Mon Dec 31, 2012 5:26 am

Quickest way to get a single command to run at startup?

Sat Jan 19, 2013 8:32 pm

For some reason, my WiFi won't connect unless I run

Code: Select all

sudo ifup wlan0
right at startup. I want to be able to make the Pi (running the latest stable Raspbian release) run this command automatically at boot so I can run it headless. I've been looking up stuff about startup scripts, but it looks like a lot of work to get just one line to run, so I'm wondering, does anyone know of a quick/easy way to do this?

andrum99
Posts: 1220
Joined: Fri Jul 20, 2012 2:41 pm

Re: Quickest way to get a single command to run at startup?

Sat Jan 19, 2013 8:46 pm

The standard way to run commands you need executed at startup that are specific to the machine is to put them into the /etc/rc.local file. You would just use:

Code: Select all

ifup wlan0
since /etc/rc.local gets run by root at startup. The rc.local file is executed after system services are started, just before users are allowed to log in. Make sure you put the command before the 'exit 0' - this line needs to be the last thing in the file.

Cheers

Andrew.

Mobius
Posts: 238
Joined: Thu Aug 30, 2012 1:07 am
Location: San Angelo, Texas USA

Re: Quickest way to get a single command to run at startup?

Sat Jan 19, 2013 8:53 pm

You really shouldn't have to issue that command to get your wifi up. Do you have the line "auto wlan0" in your interfaces file?

Anyway. the rc.local file mentioned does execute commands near the end of bootup. If you wanted to wait until you logged in for the command to execute, then you could edit the ".profile" file in your $HOME folder.

mpalomer
Posts: 26
Joined: Mon Dec 31, 2012 5:26 am

Re: Quickest way to get a single command to run at startup?

Sat Jan 19, 2013 9:01 pm

andrum99 wrote:
Cheers

Andrew.
It works. Thanks!

mpalomer
Posts: 26
Joined: Mon Dec 31, 2012 5:26 am

Re: Quickest way to get a single command to run at startup?

Sat Jan 19, 2013 9:28 pm

Mobius wrote:You really shouldn't have to issue that command to get your wifi up. Do you have the line "auto wlan0" in your interfaces file?
I do. However I set it up so that it could have a static IP address. When I set it to DHCP, I don't get this problem. The contents of the interfaces file are:

Code: Select all

auto lo
iface lo inet loopback

# The network interface
auto eth0
iface eth0 inet static
iface wlan0 inet static

address 192.168.2.101
gateway 192.168.2.1
netmask 255.255.255.0
network 192.168.2.1
broadcast 192.168.1.255

auto wlan0
allow-hotplug wlan0
iface wlan0 inet manual
wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf
Do you see anything I should change/add/remove to stop this issue?

Mobius
Posts: 238
Joined: Thu Aug 30, 2012 1:07 am
Location: San Angelo, Texas USA

Re: Quickest way to get a single command to run at startup?

Sun Jan 20, 2013 12:51 am

I've found that if both eth0 and wlan0 are set to static, then each has to have the appropriate lines following it. Also, you don't have the "auto wlan0" line and you don't have the lines for the SSID and encryption key for the wireless connection. I'm surprised that it connects at all. Here is my interfaces file where I have separate static addresses set up for the ethernet and the wireless. They could be the same but it actually allows me have both connected at the same time and able to access the Pi through two different ports at the same time.

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.1.66
netmask 255.255.255.0
gateway 192.168.1.1

auto wlan0
iface wlan0 inet static
address 192.168.1.67
netmask 255.255.255.0
gateway 192.168.1.1
wireless-essid myroutername
wireless-key mykey
Please note that the SSID and key syntax is for a WEP key. A WPA/WPA2 key requires different syntax but you should be able to find that info with a web search.

mpalomer
Posts: 26
Joined: Mon Dec 31, 2012 5:26 am

Re: Quickest way to get a single command to run at startup?

Sun Jan 20, 2013 1:04 am

Mobius wrote:I've found that if both eth0 and wlan0 are set to static, then each has to have the appropriate lines following it. Also, you don't have the "auto wlan0" line and you don't have the lines for the SSID and encryption key for the wireless connection. I'm surprised that it connects at all. Here is my interfaces file where I have separate static addresses set up for the ethernet and the wireless. They could be the same but it actually allows me have both connected at the same time and able to access the Pi through two different ports at the same time.

Code: Select all

auto lo
iface lo inet loopback

iface eth0 inet static
address 192.168.1.66
netmask 255.255.255.0
gateway 192.168.1.1

auto wlan0
iface wlan0 inet static
address 192.168.1.67
netmask 255.255.255.0
gateway 192.168.1.1
wireless-essid myroutername
wireless-key mykey
Please note that the SSID and key syntax is for a WEP key. A WPA/WPA2 key requires different syntax but you should be able to find that info with a web search.
If I don't use and never plan on using the ethernet port, can I leave out the four lines pertaining to eth0?

Mobius
Posts: 238
Joined: Thu Aug 30, 2012 1:07 am
Location: San Angelo, Texas USA

Re: Quickest way to get a single command to run at startup?

Sun Jan 20, 2013 4:35 am

In that case, just use the line "iface eth0 inet dhcp" and delete the others.

lardconcepts
Posts: 43
Joined: Mon Feb 04, 2013 11:32 am

Re: Quickest way to get a single command to run at startup?

Sat Mar 02, 2013 8:39 am

Post deleted, and I deeply apologise for the concern and upset I have caused by posting my "Quickest way to get a single command to run at startup?" question in the "Quickest way to get a single command to run at startup?" thread.
Last edited by lardconcepts on Sat Mar 02, 2013 9:48 am, edited 2 times in total.

Spid
Posts: 525
Joined: Sat Jan 19, 2013 12:47 pm

Re: Quickest way to get a single command to run at startup?

Sat Mar 02, 2013 9:33 am

I personally find HIJACKING threads is disrespectful to the original poster and your post does not enhance any solution to the problem he has had, and in fact would say it takes the thread in a different direction.

At the end of the day this forum has a SEARCH BOX and would expect all your answers are in the forum somewhere :twisted: :twisted: :twisted: :twisted:
I will always assume you are running Raspbian for desktop and Raspbmc for XMBC !

lardconcepts
Posts: 43
Joined: Mon Feb 04, 2013 11:32 am

Re: Quickest way to get a single command to run at startup?

Sat Mar 02, 2013 9:48 am

Spid wrote:I personally find HIJACKING threads is disrespectful to the original poster
I'm so terribly sorry for your upset on behalf of the OP. I apologise deeply on behalf of myself and my peoples and hope you are able to overcome this grave insult...
Spid wrote:At the end of the day this forum has a SEARCH BOX
That'll be the
Lardconcepts wrote:I was searching and it seemed the right title.
bit then...

Return to “Beginners”