Why does grep call /etc/init.d/network?

Hi,

Is this a feature, or did I miss something?

root@aaa:/etc/config# opkg list | grep bash
Syntax: /etc/init.d/network [command]

Available commands:
	start           Start the service
	stop            Stop the service
	restart         Restart the service
	reload          Reload configuration files (or restart if service does not implement reload)
	enable          Enable service autostart
	disable         Disable service autostart
	enabled         Check if service is started on boot
	running         Check if service is running
	status          Service status
	trace           Start with syscall trace
	info            Dump procd service info

root@aaa:/etc/config#

But wait there is more!

#grep screen abcjdjd 
Syntax: /etc/init.d/network [command]

Available commands:
	start           Start the service
	stop            Stop the service
	restart         Restart the service
	reload          Reload configuration files (or restart if service does not implement reload)
	enable          Enable service autostart
	disable         Disable service autostart
	enabled         Check if service is started on boot
	running         Check if service is running
	status          Service status
	trace           Start with syscall trace
	info            Dump procd service info

#

Why does grep call /etc/init.d/network ?

#grep
Syntax: /etc/init.d/network [command]

Available commands:
start Start the service
stop Stop the service
restart Restart the service
reload Reload configuration files (or restart if service does not implement reload)
enable Enable service autostart
disable Disable service autostart
enabled Check if service is started on boot
running Check if service is running
status Service status
trace Start with syscall trace
info Dump procd service info

This command looks fine, but the response is odd.

Try rebooting the device and then run the commands again.

1 Like

Why? Because YOU symlinked grep command to script.

command -v grep

YOU wrote nonsense. Or tell me how to verify your claim?

#ls -l /bin/grep 
lrwxrwxrwx    1 root     root             7 Jul 15 22:14 /bin/grep -> busybox
#which grep
/bin/grep
#command -v grep
grep
#
#env
USER=root
SSH_CLIENT=10.x.x.x 49481 22
SHLVL=1
HOME=/root
OLDPWD=/etc
SSH_TTY=/dev/pts/0
PS1=#
ENV=/etc/shinit
LOGNAME=root
TERM=xterm-256color
PATH=/usr/sbin:/usr/bin:/sbin:/bin
SHELL=/bin/ash
PWD=/tmp
SSH_CONNECTION=10.210.10.53 49481 10.210.10.3 22
type grep

Already done.

Please connect to your OpenWrt device using ssh and copy the output of the following commands and post it here using the "Preformatted text </> " button:
grafik
Remember to redact passwords, MAC addresses and any public IP addresses you may have:

ubus call system board
alias
busybox grep 1 </dev/null
1 Like

no, the intent was that you would enter the complete line:

type grep

(including the type part into the command line).

3 Likes

#type grep
grep is a function

#ubus call system board
{
	"kernel": "5.15.162",
	"hostname": "tplink650",
	"system": "MediaTek MT7621 ver:1 eco:3",
	"model": "TP-Link RE650 v2",
	"board_name": "tplink,re650-v2",
	"rootfs_type": "squashfs",
	"release": {
		"distribution": "OpenWrt",
		"version": "23.05.4",
		"revision": "r24012-d8dd03c46f",
		"target": "ramips/mt7621",
		"description": "OpenWrt 23.05.4 r24012-d8dd03c46f"
	}
}
#alias
ll='ls -alF --color=auto'
more='less'
vim='vi'
#busybox grep 1 </dev/null
#

What is installed for grep, busybox or package

Is this grep issue on the same device as the one here:

If so, seems like something got really messed up, and the best bet is to reset to defaults (take a backup first).

Yes, it is.

I took a backup earlier before I tried to install those packages.

I am off to bed for now, and will try again on the weekend.

I know that I can reinstall from the backup.

Well, that's your problem, something has redefined grep to be a function so it's not calling the binary. This probably came from sourcing a script somewhere, sleuthing needed.

Do this and see if it's fixed.

unset -f grep
type grep

Should say something like grep is /bin/busybox or similar.

2 Likes

Other troubleshooting:

set -x
grep grep /etc/profile.d/*
set +x
/bin/grep -H grep /etc/profile.d/*
1 Like

Works now. Oh well.

root@tplink650:~# unset -f grep
root@tplink650:~# type grep
grep is /bin/grep
root@tplink650:~# grep grep
^C
root@tplink650:~# grep cat /etc/config/system

Quoting is important.

$ grep '()' /etc/init.d/network
init_switch() {
        setup_switch() { return 0; }
start_service() {
reload_service() {
...

$ grep () /etc/init.d/network

$ type grep
grep is a function

$ grep
Syntax: /etc/init.d/network [command]

Available commands:
        start           Start the service
        stop            Stop the service
        restart         Restart the service
        reload          Reload configuration files (or restart if service does not implement reload)
        enable          Enable service autostart
        disable         Disable service autostart
        enabled         Check if service is started on boot
        running         Check if service is running
        status          Service status
        trace           Start with syscall trace
        info            Dump procd service info
2 Likes