brenton
September 3, 2020, 10:28am
1
I've created a script with various switches for managing sqm. The script works fine when called like:
/usr/sbin/sqm -d
...or... /usr/sbin/test -d
But the script does nothing when called like:
sqm -d
...or... test -d
I've tried /sbin and /usr/sbin. Does anyone know what's missing for this to work?
Thank you
trendy
September 3, 2020, 10:30am
2
What is your path?
echo $PATH
1 Like
brenton
September 3, 2020, 10:31am
3
echo $PATH
output shows:
/usr/sbin:/usr/bin:/sbin:/bin
trendy
September 3, 2020, 10:32am
4
Should work.
Verify with which sqm
1 Like
brenton
September 3, 2020, 10:35am
5
I've called it various names and rebooted. None work
Whats odd is that it knows the command is there otherwise it would respond:
-ash: example: not found
trendy
September 3, 2020, 10:37am
6
What does which sqm
say?
What is the content of the file?
1 Like
brenton
September 3, 2020, 10:38am
7
Here's what's happening:
root@OpenWrt:~# test -d
root@OpenWrt:~#
root@OpenWrt:~# /sbin/test -d
-disabling cake qos & wifi
1 Like
brenton
September 3, 2020, 10:40am
8
File contents are just bash script.
While ... do
and various functions
brenton
September 3, 2020, 10:41am
9
root@OpenWrt:~# which test
/sbin/test
trendy
September 3, 2020, 10:42am
10
What is the content of the file?
1 Like
brenton
September 3, 2020, 10:49am
11
trendy
September 3, 2020, 10:58am
12
There is already a file named test in /usr/bin which has higher priority in the path.
Other than that I added a couple of echos in the beginning of your file and it was printed fine when calling it without full path.
#!/bin/sh
echo "test"
echo
usage="$(basename "$0") -- enable cake layer sqm qos
1 Like
brenton
September 3, 2020, 11:01am
13
Ok cool thanks. I'll try persist with it a bit further.
Thanks for confirming it works.
Edit: I renamed it 'cake'
and now it works fine. Thanks @trendy
2 Likes
trendy:
which
It's best to use type
to identify the command, because which
may return incorrect result:
# which test
/usr/bin/test
# type test
test is a shell builtin
The binary and the shell builtin may have different version and support different syntax.
brenton
September 3, 2020, 11:49am
16
Thanks @vgaetera that works better.
I ended up finding it hiding in /rom/usr/bin/test
Looks like my bad luck choosing names that were already in use.
Thanks again guys
1 Like
brenton:
/rom/usr/bin/test
If you need to run a BusyBox applet, there's a simpler way:
busybox test
This allows to call applets even without symlinks.
See also: Limit BusyBox applets to /bin and /sbin
1 Like
trendy
September 3, 2020, 12:56pm
18
root@magiatiko:[~]#la /usr/bin/t*
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/tail -> ../../bin/busybox
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/tee -> ../../bin/busybox
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/test -> ../../bin/busybox
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/time -> ../../bin/busybox
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/top -> ../../bin/busybox
lrwxrwxrwx 1 root root 17 Jun 30 10:34 /usr/bin/tr -> ../../bin/busybox
-rwxr-xr-x 1 root root 48.7K Jun 30 10:34 /usr/bin/tvservice
test confirms what you say, however top and tr don't.
root@magiatiko:[~]#type tr
tr is /usr/bin/tr
root@magiatiko:[~]#which tr
/usr/bin/tr
root@magiatiko:[~]#type test
test is a shell builtin
root@magiatiko:[~]#type top
top is /usr/bin/top
Or wasn't that your point?
What I wanted to make sure is that there wasn't any other sqm file with higher priority in the PATH.
1 Like
Shell builtins should have the highest priority and override binaries in PATH
.
Assuming that sqm
is not compiled in the shell, using which
is fine.
However, in general case which
ignores shell builtins.
It may lead to an incorrect result , thus using type
over which
is preferable.
trendy
September 3, 2020, 1:49pm
20
I got you, but why top or tr don't return type shell builtin then?
1 Like
This means they are not compiled into ash
, but still may be parts of busybox
:
# readlink -f $(type -p top)
/bin/busybox
# readlink -f $(type -p tr)
/bin/busybox
# opkg files busybox | grep -e /top$ -e /tr$
/usr/bin/tr
/usr/bin/top
2 Likes