Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sh: ip: command not found centos

Tags:

bash

php

centos

I am debugging some code and I have the following line that I think is causing errors in my php log sh: ip: command not found Any ideas as to why or what packages are missing on the Centos server?

Code:

exec("ip tunnel show | cut -f1 -d' ' | cut -f1 -d':'", $someVar);

like image 273
Jess McKenzie Avatar asked Dec 25 '22 12:12

Jess McKenzie


2 Answers

Add path: replace ip by /sbin/ip.

like image 77
Cyrus Avatar answered Jan 03 '23 01:01

Cyrus


The 'ip' command resides in sbin directory, which may not be in your PATH env variable. There could be more such commands not having their path part of PATH env variable. You need to set /sbin in your path by following below step.

In your shell script, add following two lines BEFORE your exec() line, followed by your exec line:

exec("PATH=\$PATH:/sbin ip tunnel show | cut -f1 -d' ' | cut -f1 -d':'", $someVar);
like image 26
Prasanna Avatar answered Jan 03 '23 01:01

Prasanna