Unable to use service inside script on openwrt 18.06

Hey everyone,

I am unable to use the service command inside a script. I have another device running openwrt 22.03 and it works fine, so I wonder if version 18 has some restrictions on the usage of service.

The error messages look like this:

99-mode2_to_1.sh: line 21: service: not found
99-mode2_to_1.sh: line 22: service: not found
99-mode2_to_1.sh: line 23: service: not found
99-mode2_to_1.sh: line 24: EOF: not found

The inside of this script looks like this:

#!/bin/sh /etc/rc.common
#Convert the device from operation mode 2 to operation mode 1
[ "$(uci -q get network.lan.proto)" = "dhcp" ] && echo "ERROR: Device is already in Dumb-AP mode" && exit 0
uci -q batch << EOI
set dhcp.lan.ignore='1'
set network.lan.ifname='eth1'
del network.lan.ipaddr
del network.lan.netmask
del network.lan.dns
del network.lan.ip6assign
del network.lan.proto
set network.lan.proto='dhcp'
del wireless.default_radio0.network
del wireless.default_radio1.network
set wireless.default_radio0.network='lan'
set wireless.default_radio1.network='lan'
set network.wan.disabled="1"
set network.wan6.disabled="1"
service nodogsplash stop
service nodogsplash disable
service network restart

The device is a 8devices komican, unfortunately I can't upgrade as this device is unsupported.

Insert this as the line #2:

. /etc/profile

The EOF looks redundant, remove it.

I tried like this but it didn't work unfortunately

#!/bin/sh /etc/profile

I also tried like this, to no avail:

#!/bin/sh . /etc/profile

So you're running a manufacturer build, there is no way to know what is and is not included.

You can usually call init.d scripts directly such as
/etc/init.d/nodogsplash stop
This will also work on official builds.

1 Like

That checks out! Only the EOF not found persists, should I perhaps replace it with an exit 0?

There's no reason for the EOF line you can remove it. The end of a script file implies an exit 0.

1 Like

If I understood you correctly, you are saying that this firmware is not official openwrt? Because I assure you that it is.

I remember using this in one of my earlier posts, but I prefered using service because it made the code look cleaner when paired with network restart xd

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.