2

I would like to spawn a persistent netcat server. My command of choice is the following:

echo "bash -c \"while [ 1 ]; do nc -l -p 1111 >> check; done\"" | at now

I am wondering how I can get the PID of the process created by at so that I can easily put the server to sleep when needed.

3

This is a tad tricky because of quoting, note change from " to '

The following will work if you submit your at job via at -f file

at -f nc.on now
cat nc.on
bash -c 'while [ 1 ]; do echo $$ > /var/run/atnc.pid; nc -l -p 1111  >> check; done'

the file /var/run/atnc.pid will have the process id of the bash which is running nc

You can cat the file to get the bash process id and kill it, terminating nc. Then rm /var/run/atnc.pid (optional).

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.