0

I'm trying to create a simple script (one liner, actually) that takes the content of the a file, makes it random, and provides the output to netcat as the connection destination.

This is what I thought was needed:

NCIP=$(sort --random-sort /root/list.csv | head -n 1) | nc -zv -w 2 $NCIP 443

My idea is to set the variable NCIP based on the output of sort and head, and have the nc command call it. For some reason, I can't seem to make this work.

Any pointers would be greatly appreciated.

  • If you want to get one random line from a file, you could use shuf instead of sort. Both are shipped in the coreutils package. Example: shuf -n 1 /root/list.csv – Victor Jerlin Mar 28 '17 at 21:47
1

You need either to

$ NCIP=$(sort --random-sort /root/list.csv | head -n 1) ; nc -zv -w 2 $NCIP 443

or

$ sort --random-sort /root/list.csv | head -n 1 | nc -zv -w 2 -p 443
  • Since you wrote yesterday that this solution worked for you (especially the first one), why not to accept this answer as solution? – George Vasiliou Mar 29 '17 at 9:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.