LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   need help running a shell program on startup as root in a terminal (https://www.linuxquestions.org/questions/linux-general-1/need-help-running-a-shell-program-on-startup-as-root-in-a-terminal-824156/)

bolter40k 08-04-2010 11:36 AM

need help running a shell program on startup as root in a terminal
 
Hi,

I am running Linux Mint 9

I play xbox live and run it through my laptops wireless network connection so i dont have to pay 100 dollars for the usb wireless adapter for the xbox. In windows 7 this is easy to configure so that when i turn my laptop on and then xbox it automatically connects. I wrote a program that enables ip forwarding it is written as follows
Code:

#!/bin/bash -e
ifconfig eth0 up
ifconfig eth0 192.168.2.0
echo "1" > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o wlan0 -s 192.168.2.0/24 -j MASQUERADE

but when i run it as root nothing happens and my xbox wont connect to live. But when i manually type in these commands after su to root it works

also my startup file is rc.local as ive read an in it ive written the path to my program so it will be run how can i tell it is being run and how do i tell it to run as root?
Code:

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
/home/dylan/xboxlive.sh

thanks, bolter40k

qweasd 08-04-2010 11:53 AM

May be it's because bash -e exits right after a command returns a non-zero value.

bolter40k 08-04-2010 12:33 PM

changed it it still wont work

qweasd 08-04-2010 12:52 PM

Quote:

also my startup file is rc.local as ive read an in it ive written the path to my program so it will be run how can i tell it is being run and how do i tell it to run as root?
It will run as root. If you are really suspecting that rc.local is not being run, try echoing something from there, like echo hello > /tmp/hello .

Does your script work if you run it from a terminal, as root, after the computer is fully booted? If so, then may be your desktop environment (which, I guess, starts up after rc.local) is messing up your card settings.

bolter40k 08-04-2010 01:19 PM

Quote:

Originally Posted by qweasd (Post 4055785)
It will run as root. If you are really suspecting that rc.local is not being run, try echoing something from there, like echo hello > /tmp/hello .

Does your script work if you run it from a terminal, as root, after the computer is fully booted? If so, then may be your desktop environment (which, I guess, starts up after rc.local) is messing up your card settings.

well for some reason my script doesnt work when run by itself (right click>open as admin) doesnt seem to work at all
I cant seem to figure out where i went wrong especially considering when i enter these commands in myself it always works

michaelk 08-04-2010 01:37 PM

What are the permissions of your script?

bolter40k 08-04-2010 01:43 PM

Quote:

Originally Posted by michaelk (Post 4055843)
What are the permissions of your script?

this is only way i know of gettin permissions in a terminal i hope its what your looking for

Code:

dylan@dylan-laptop ~ $ ls -l
total 40
drwxr-xr-x  2 dylan dylan 4096 2010-07-31 14:45 Desktop
drwxr-xr-x  8 dylan dylan 4096 2010-07-31 19:05 Documents
drwxr-xr-x  7 dylan dylan 4096 2010-08-04 13:53 Downloads
drwxr-xr-x  5 dylan dylan 4096 2010-07-31 22:15 Ebook
drwxr-xr-x 133 dylan dylan 4096 2010-07-31 23:10 Music
drwxr-xr-x  6 dylan dylan 4096 2010-08-03 04:19 Pictures
drwxr-xr-x  2 dylan dylan 4096 2010-07-31 14:45 Public
drwxr-xr-x  2 dylan dylan 4096 2010-07-31 14:45 Templates
drwxr-xr-x  5 dylan dylan 4096 2010-08-01 01:53 Videos
-rwxr-xr-x  1 dylan dylan  173 2010-08-01 21:36 xboxlive.sh


qweasd 08-04-2010 02:48 PM

What if you run it like this:

Code:

cd
su
./xboxlive.sh


bolter40k 08-04-2010 03:47 PM

Quote:

Originally Posted by qweasd (Post 4055910)
What if you run it like this:

Code:

cd
su
./xboxlive.sh


yes that worked thanks... so it has to be executed as root but why doesnt it run at start up

bolter40k 08-04-2010 05:25 PM

bump

qweasd 08-04-2010 07:39 PM

May be your DE is messing with the card? What does /sbin/ifconfig output look like after you boot?


All times are GMT -5. The time now is 10:28 AM.