5

In my sh or tcsh I can call netstat without problems. With Bash however, I get the message:

bash: netstat: command not found

The PATH variable is exactly the same for all shells:

PATH=/usr/lpp/Printsrv/bin:/usr/lpp/java/J6.0/bin:/EXEX/exec:/bin:/usr/sbin:/etc:/usr/lpp/perl/bin:.:/usr/lpp/ported/bin:.:.

Netstat is in the /bin directory and so should be included in the PATH...

Any ideas?

Thanks!

jww
  • 97,681
  • 90
  • 411
  • 885
Klaus Schulz
  • 527
  • 1
  • 5
  • 20
  • 1
    Does `/bin/netstat` run? About the only thing I can think of that might be a problem here, is there's a `netstat` higher up the path that's somehow not valid. – Sobrique Feb 02 '15 at 10:00
  • 1
    What is the result of `which netstat`? Your path looks very odd (most likely incorrect) and is missing some standard folders. Debug the issue with BASH and treat the other shells as a red herring. – Philip Couling Feb 02 '15 at 10:08
  • In bash, please give us the output of these commands `echo "$PATH"` and `which netstat`, and also attempt to run `/bin/netstat` as suggested by @couling and @Sobrique – Aaron McDaid Feb 02 '15 at 10:10
  • $/bin/netstat/$ runs fine. :) $which$ doesn't run under bash but with tcsh. $which which$ gives $which: shell built-in command.$ – Klaus Schulz Feb 02 '15 at 10:30
  • So something is very wrong with your path then – Philip Couling Feb 02 '15 at 10:37
  • 3
    Somebody pulled a prank on you and put this line in your `.bashrc`: `alias netstat='echo bash: netstat: command not found'` – Ruud Helderman Feb 02 '15 at 12:48
  • @Ruud LOL I'll have to add that to my list – Philip Couling Feb 02 '15 at 12:50

1 Answers1

6

We don't quite have enough information yet to state what's gone wrong here, but I'm going to go out on a limb and suggest your path isn't what you think it is, not to mention the path you quote is very non-standard and most likely not what you want.

What you say your path is...

The path you quote looks like this when broken down:

/usr/lpp/Printsrv/bin
/usr/lpp/java/J6.0/bin
/EXEX/exec
/bin
/usr/sbin
/etc
/usr/lpp/perl/bin
.
/usr/lpp/ported/bin
.
.

The current working directory (.) three times over won't cause a problem, but it does look a little odd.

You're missing the standard directory /usr/bin. And if you have /usr/sbin you ought to have /sbin in there as well for consistency.

I can't imagine why you would ever put /etc in your path. There should never be executables in that directory.

What your path actually is...

There should be no difference between the shells. It's highly unlikely that you've found a bug in the shells here so lets assume your path isn't quite the same in each and try to figure out why it looks like it does...

All shells should tell you that your path is the same thing with BOTH of the two commands:

# The PATH variable
echo "$PATH"

# The PATH environment variable
env | /bin/grep PATH

Remember there are two kinds of variable. Internal Variables and Environment Variables. PATH should be an environment variable.

I'm not sure how you found the following line:

PATH=/usr/lpp/Printsrv/bin:/usr/lpp/java/J6.0/bin:/EXEX/exec:/bin:/usr/sbin:/etc:/usr/lpp/perl/bin:.:/usr/lpp/ported/bin:.:.

If this was taken from your .profile or .bashrc then it should be exported to ensure the PATH gets set as an environment variable.

export PATH=/usr/lpp/Printsrv/bin:/usr/lpp/java/J6.0/bin:/EXEX/exec:/bin:/usr/sbin:/etc:/usr/lpp/perl/bin:.:/usr/lpp/ported/bin:.:.
tripleee
  • 175,061
  • 34
  • 275
  • 318
Philip Couling
  • 13,581
  • 5
  • 53
  • 85
  • 2
    Having the current directory in your `PATH` is strongly discouraged for security reasons. If you know and trust `./command` then use `./command` instead of `command`; if you don't, well, then, that's the reason this is discouraged. – tripleee Feb 02 '15 at 11:30
  • The observation that the `PATH=` assignment could be obtained from a configuration file, rather than actually what the shell truly operates with, may be significant. If something overrides your `.bashrc` or similar then what you see there may not at all be the actual truth. – tripleee Feb 02 '15 at 11:32
  • I created a `.profile` and set `PATH=/usr/lpp/java/J6.0/bin:/EXEX/exec:/bin:/usr/sbin:/sbin` as you suggested. Executing both `echo "$PATH"` and `env | /bin/grep PATH` give the same result for all shells: the PATH I specified in `.profile`. However, `netstats` runs in all shells but bash... – Klaus Schulz Feb 02 '15 at 12:07
  • @tripleee: the PATH assignment should be obtained from my file. If I specify the path to another Java-SDK, running `java -version` gives the correct answer. – Klaus Schulz Feb 02 '15 at 12:23
  • @KlausSchulz the point I was making is that you MUST `export PATH`. It's not sufficient simply to set it – Philip Couling Feb 02 '15 at 12:46
  • `netstat` or `netstats`? – tripleee Feb 02 '15 at 12:51
  • I think I did. My .profile is `PATH=/usr/lpp/java/J7.0/bin:/EXEX/exec:/bin:/usr/sbin:/sbin export PATH` – Klaus Schulz Feb 02 '15 at 12:51
  • `netstat`(typo in my comment, sorry) – Klaus Schulz Feb 02 '15 at 12:53
  • There's so many things you could have done to mess this up, its very hard to understand what your seeing because it's not making any sense yet. Have you checked netstat is in `/bin` ie: `ls -l /bin/netstat` – Philip Couling Feb 02 '15 at 13:04
  • Result is `erwxrwxrwx 1 OMVS OMVSGRP1 8 Jun 4 2013 /bin/netstat -> ONETSTAT`. Well, I am not very experienced with Unix (here: IBM Unix System Services for z/OS) so I have few ideas how to solve this issue.... – Klaus Schulz Feb 02 '15 at 13:13
  • Okay. Follow the chain. What's the result of `ls -l /bin/ONETSTAT`. What you've found there is a symbolic link. Its a bit like a windows shortcut for unix. – Philip Couling Feb 02 '15 at 13:14
  • `ls: FSUM6785 File or directory "/bin/ONETSTAT" is not found` Both bash and tcsh... – Klaus Schulz Feb 02 '15 at 13:19
  • 3
    Bingo! There's why bash can't find `/bin/netstat` the program it points to doesn't exist. Something's got screwed up on your system so you're going to need to find that program (and install it if it doesn't exist). Start by checking the other three directories `/usr/bin` `/sbin` `/usr/sbin` to see if `ONETSTAT` has been moved there. As for why this worked on the other shells... that's really not very clear. The most likely thing is that something in their profiles is creating an alias or they are finding another `netstat`. – Philip Couling Feb 02 '15 at 13:29
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/70045/discussion-between-couling-and-klaus-schulz). – Philip Couling Feb 02 '15 at 13:32
  • The conversation was continued in chat but I would be interested in if it got solved. – bomben Nov 01 '18 at 11:14