What's wrong with this script? arp: not found

Hi,

Can't I use the arp command in the shell script?
Should I use cat /proc/net/arp instead of the arp command?

root@OpenWrt:~# arp -a
IP address       HW type     Flags       HW address            Mask     Device
192.168.1.104    0x1         0x6         *     *        br-lan
192.168.1.117    0x1         0x2         *     *        br-lan
192.168.1.133    0x1         0x0         *     *        br-lan
192.168.1.152    0x1         0x2         *     *        br-lan
192.168.1.162    0x1         0x0         *     *        br-lan
192.168.1.187    0x1         0x2         *     *        br-lan
192.168.1.218    0x1         0x2         *     *        br-lan
root@OpenWrt:~# cat ./test.sh 
#!/bin/sh
arp -a
root@OpenWrt:~# ./test.sh 
./test.sh: line 2: arp: not found

Can't I use the ARP command in the shell script?

Seems to be something special with "arp", as which does not find it although the command works:

root@router1:~# arp
IP address       HW type     Flags       HW address            Mask     Device
192.168.1.170    0x1         0x0         7c:46:85:..:..:..     *        br-lan
...
root@router1:~# which arp
root@router1:~#

Somehow deeply built-in into busybox?

same way as "cd" ?

root@OpenWrt:~# cat ./test.sh 
#!/bin/sh
cd /
root@OpenWrt:~# ./test.sh 
root@OpenWrt:~# cd /
root@OpenWrt:~# ./test.sh 
./test.sh: line 2: arp: not found
root@OpenWrt:~# cat ./test.sh 
#!/bin/sh
arp
root@OpenWrt:~# which arp
root@OpenWrt:~#

It seems that only arp has failed.
I built the openwrt image with the default configuration.

Could you use ip as an alternative
ip -4 neigh
or
ip neigh

1 Like

or even
cat /proc/net/arp

3 Likes

that's because on the default openwrt installation it's just a (b(a)sh) function:

If you want to use the function in a script, you could include / source /etc/profile... But yeah, it's not the full fledged arp utility.

3 Likes

nice catch :wink:

...or you can just define the same function in your own script. Basically just use

cat /proc/net/arp

https://openwrt.org/docs/guide-developer/networking/network.interfaces#old_and_deprecated_utilities_for_networking_and_traffic_control

# type arp
arp is a shell function

# grep arp /etc/profile
[ -x /usr/bin/arp -o -x /sbin/arp ] || arp() { cat /proc/net/arp; }
1 Like