telnet is not part of the nsh install. so you would need telnet installed on the client system.
You need to have telnet installed on the client machine and then use nexec command to check the availability of any port using nsh.
nexec telnet hostname port
I NSHed into the server in question and ran the following nexec telnet hostname port. This is what I did and the results
I started with cd //sl01n10 #worked as it should
I then ran 'nexec telnet sl01n10 22' and the first time I got timeout's, the second time after logging out and back into the cli I got
'nexec: Error accessing host telnet: i/o error
Unable to access telnet I/O error'
telnet is on the server and port 22 is open. Is their something more I need to add?
if you run 'telent host port' that is calling the telnet command from your client system, even if you are cd'd to some other system...
when you run 'nexec telnet xxx xx' you are not using the correct syntax for the nexec command. you need to either do
nexec -e telnet host port
nexec target telnet host port
that will run the telnet on the target system.
Thank you. That worked for me.
Telnet opens a shell on a successful connection, so you can't just run telnet like that or it will hang waiting for a response.Also, the output refreshes when the console opens, and you won't be able to see the response text in NSH as I think it outputs it to console (neither stdout nor stderr).
The exit code is also not 0 when the telnet success if you do that so you won't be able to properly evaluate the response.
For this reason we've used the PortQry.exe executable or T4EPortPing which is part of the Tools4Ever bundle. Both of these tools are not native on Windows and must be copied before they can be used, but are much more suited to do what you need.
On Unix, you could copy and use a small perl script that tries to open a socket on a given address/port, or use Expect to simply use telnet instead.
I believe you have covered my current issue in your response but I am still not sure which way to go.
Is what a I am experiencing below what you are talking about?
The problem is then when trying to capture the output on the screen I get only
'trying x.x.x.x ...' in my output log. I do not get the results of the test.
I did try the following in the script:
nexec -e telnet $HOST 25
nexec -e telnet $HOST 587
What is the return code if not 0 for success?
Just run this command manually on your own system while in a command prompt, and you`ll see what I mean. The telnet command is meant to open a terminal when it can connect. The only way that it will return with an exit code the way you call it now is if the connection times out due to failure. You will never be able to get the success exit code because the telnet command will just stay open waiting for user input.
If you are nexec’ing the command on the box itself, why not use netstat ?
If you just wanna see if there's a port XZY listening on the server, nexec -e cmd /c netstat -an | grep LISTENING | grep ":PORT_NUMBER " should do the trick yes. You can check the value of $? right after to see if it found it or not (0 = found, 1 = not). If you want a silent grep, use grep -q for the last grep.
However, it doesn't actually "test" it. It just says the system has an open port with that number, but it could be frozen, or a local firewall could prevent access to it. I would do both to be thorough, and that's where a utility such as portqry.exe or t4eportping.exe comes in handy.
Actually that was what I did but without the use of nexec since it is native to the shell or at least it looks that way to me. And I am on the server that it is being run against.
The script is working.
if you are cd'd to the target and run netstat it should run in the context of the target system w/o a nexec.
Netstat is one of the commands that is a link to nexec, so yeah. I still prefer to call it explicitly though because I want to run it through cmd /c, that's why.