OpenWrt Forum Archive

Topic: How to create an auto-start the process

The content of this topic has been archived on 22 Apr 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

Hello!

I want to create an automatic startup files:
/etc/init.d/test
Code:
#----------------------------------------------------------------------------------------------------------------------
#!/bin/sh /etc/rc.common
START=50
username='uci get test.@interface[0].current'
password=`uci get test.@interface[$i].password`
ifname=`uci get test.@interface[$i].ifname`
start() {
test $username $password $ifname &
}
stop() {
killall test
}
restart() {
stop test
start test
}
#----------------------------------------------------------------------------------------------------------------------


Read automatically run the following file information:
/etc/config/test
Code:
#------------------------------------------------------------------------------------------------------------
config interface 'Default_configuration'
        option ifname 'eth0'
        option username 'user1234'
        option password 'pass1234'
#------------------------------------------------------------------------------------------------------------
But unfortunately, this is wrong,

Can you help me to correct an error.
Thank you very much.

Best regards,
Tony

hxzhyx wrote:

But unfortunately, this is wrong,

Can you help me to correct an error.

What is exactly the error?

test.@interface[0].current is not defined
test.@interface[0].username is

robthebrew wrote:

test.@interface[0].current is not defined
test.@interface[0].username is


Code:
-------------------------------------------------------------------------
#!/bin/sh /etc/rc.common

START=50

current='uci get test.@test[0].current'
ifname='uci get test.@interface[0].ifname'

for i in 'seq 0 10';do
        username='uci get test.@test[$i].username';
        if [ $username = $current ];then
                password='uci get test.@test[$i].password'
                break
        fi;
done

start() {
test $current $username $password $ifname
}

-------------------------------------------------------------------------

I modify the code based on a similar startup script.
Run.

root@OpenWrt :/etc/init.d # ./test start
sh: get: unknown operand

Application does not recognize $
I think username acquisition failed.

mapisto wrote:
hxzhyx wrote:

But unfortunately, this is wrong,

Can you help me to correct an error.

What is exactly the error?

I think the biggest problem is to get the user name and password failed.

No the biggest problem is that your shell code does not make any sense.
The "current" and "ifname" assignments should be wrapped into backticks `...` or $(...) to capture the output of the uci get command and the "test" statement in start() is syntactically wrong as well.

This is exciting news, after trying, I finally succeeded, I hope to be able to help people in need.

Code:
#-------------------------------------------------------------------------
#!/bin/sh /etc/rc.common

START=50

start() {
        username="$(uci get test.@test[0].username)"
        password="$(uci get test.@test[0].password)"
        ifname="$(uci get test.@interface[0].ifname)"

test $username $password $ifname &
}
#-------------------------------------------------------------------------

Can you give us all of them (the scripts/inits) together, just for future's sake?

robthebrew wrote:

Can you give us all of them (the scripts/inits) together, just for future's sake?

I would like to complete a standard IEEE 802.1X protocol configuration page, and now has just begun, and completed only start part.The script, please refer to the contents of the above.

Is this below something you like to have?

/etc/config/test

config interface 'default_configuration'
        option ifname 'eth0'
        option username 'user1234'
        option password 'pass1234'

config test 'test'
        option ifname 'ethX'
        option username 'user12345'
        option password 'pass12345'

/etc/init.d/test

#!/bin/sh /etc/rc.common

START=50

load_test() {
        local interface username password

        config_get interface default_configuration ifname
        config_get username test username
        config_get password test password

        echo "$interface --- $username --- $password"
}

start() {
        config_load test
        config_foreach load_test test
}

/etc/init.d/test start

eth0 --- user12345 --- pass12345

(Last edited by written_direcon on 2 Apr 2013, 21:42)

The discussion might have continued from here.