The error script.sh: line 3: ifconfig: command not found
means that the shell (launched by tomcat to run the command) is searching its PATH to find the ifconfig
program, and it's not finding it. The value of the shell's PATH variable came from Tomcat, which would have gotten it from one of three places:
If Tomcat was started by a system utility (
/etc/init.d
orsystemd
for example) then tomcat would get its path from there.If tomcat was started by you running a command from your terminal, then tomcat probably got its path from your environment.
Tomcat (or any java class running inside tomcat) could change its PATH after startup.
If you're finding that the script always fails when tomcat was launched by a system utility, and it always works when tomcat was started from your terminal, then the issue is #1. The PATH which tomcat is getting from the system doesn't include the directory containing ifconfig
.
If you're finding that the script works for a while after starting tomcat, and then it starts failing until you restart tomcat, then something within tomcat is changing tomcat's PATH environment variable. Tomcat itself probably doesn't contain any code to do that, so you should look at the applications which you have deployed within tomcat.