Get lines that contain the same pattern twice or X times(source):
grep -E "(string.*){2}" file.log
Get lines that contain the same pattern twice or X times(source):
grep -E "(string.*){2}" file.log
Source: https://stackoverflow.com/a/19271368
You can achieve it in two steps:
1) You need to start nc with a named pipe (fifo) as its input:
mkfifo /tmp/fifoIn; cat /tmp/fifoIn | nc localhost 2222 &
2) Send your data from file input.txt, line by line with 2 sec delay:
cat input.txt | while read line; do echo $line; sleep 2; done > /tmp/fifoIn
I've tested it with this "server" (I'm using openbsd netcat syntax):
nc -l localhost 2222
If you don't want the new-line char after every line use echo -n
instead of echo
.
1. Get pid of specific executable:
pgrep exe_name
Install ucspi-tcp
:
apt-get install ucspi-tcp
This pacakge contains this list of tools
Create tcp server from bash using tcpserver
command from ucspi-tcp
:
# script.sh content
#!/bin/bash
# read MESSAGE
echo "message: $MESSAGE"
sleep 2
echo " message 2"
sleep 3
echo " message 3"
sleep 2
# ---- end ------- #
# Run tcpserver:
tcpserver -v -H -R IP PORT script.sh
# Open a connection:
echo "" | nc IP PORT
This tcp server can open multiple connections in parallel. Verry usefull when you want to have a mock tcpserver.
Fixed issues:
read
command doesn't work if I add it in the script(I had a client written in C++). But it did work when my client was nc
....The fix was to add \n
at the end of the string that I was sending from that client. To reproduce this, you can run a client like this: echo -n "sa" | nc IP PORT
and the script should contain a read
instruction. You will notice that the server will stop at that read
instruction.
First install xfce4-terminal
(I had some problems with lxterminal
):
apt-get install xfce4-terminal
The go here: https://github.com/chriskempson/base16-shell
Follow the steps.
I used base16_flat
theme.
Add this to ~/.basrc
:
# Display date of the command
export HISTTIMEFORMAT="%d/%m/%y %T "
# Size(nr of lines) of the history loaded in memory?
export HISTFILESIZE=10000000
# Size(nr of lines) of the history saved in file?
export HISTFILESIZE=10000000
# Path to history file.
export HISTFILE=/home/chreniuc/data/configs/.bash_history