hi everybody;
my code is cheking if a port is an actif or not with the cmd netstat -ln,I want first to enter the number of the port which I want to check it but I think that the value of $con in the second "if" is always "0" so the code give me always that the port is not used!!!
Reading from a filehandle, such as STDIN, will always read all characters up to and including the new line character(s), and save them to the variable given on the left side. That means when your user inputs (for example) "22" and then hit return, $port will actually contain "22\n" (on Unix) or "22\r\n" on Windows or "22\r" on MacOS. chomp will remove any non-printable characters at the end of the line for you. Try this small script:
See the difference?
Now when you try to match the contents of $port on line 7, Perl is trying to match (with the example 22 again) ":22<newline>" exactly. Since the port number isn't at the end of netstats output, it will never match.
As for point 3, take a look at the (aptly named) grep function.
I'd tend to use grep on an array rather than a string, for a string I'd go for something like the following with a straight regex. (Note: regex used works for my flavour of netstat and may need amending to work for you, (netstat 1.42 (2001-04-15) from net-tools 1.6)
Last edited by Skrynesaver; 05-19-2011 at 07:22 AM..
Reason: Left in final quote from cmndline development
This User Gave Thanks to Skrynesaver For This Post:
I have my firewall process running
# ps -ef | grep firewall
root 21169 1 0 08:50 ? 00:00:00 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
I wish to know what ip : port number it is using. Can you please tell me how can i find out ?
I tried the below command... (4 Replies)
I have RHEL 5.8 in our production environment. We are using SSL, my query is how to find the port used for SSL. In /etc/services, it shows 443 but when I give
netstat -tulpn | grep 443
Or
netstat -tulp | grep https
I do not get any output.
I hope, my question is clear of how to find... (4 Replies)
Hi Experts,
I am checking how to get day in Perl.
If it is “Monday” I need to process…below is the pseudo code.
Can you please prove the code for below condition.
if (today=="Monday" )
{
while (current_time LESS THAN 9:01 AM)
... (1 Reply)
Hi,
I need to create a script which checks the availability of a particular service on a particular Port on HP-Unix. Is there any command in unix wherein we can check if any port is accepting the connections now.
Thanks,
Vihang. (5 Replies)
Q1: can anyone tell me how cfgadm keeps track of the device even if the device is disconnected ,
when we disconnect a device using cfgadm
cfgadm -ys disconnect <ap_id>
then the device disappears from the lshal o/p. HAL uses libdevinfo for the device list. if the device is not there in the... (2 Replies)
Hello Mentors!
I am a new here in the furom, i hope somebody can understand my problem.
Basically we have an application here called unigraphics and being installed per station and the setup is look like this.
1. installed unigraphics UGNX3 version on every station
2. some are installed in... (1 Reply)