Netcat as DaemonWhy does cron silently fail to run sudo stuff in my script?Cron job does not fire up after a timezone changeCalling mailx from crondUsing netcat for port forwardingScreen session started from rc.local is not visible in screen -ls under rootnetcat - unable to put CLIENT IP into $VARHow do I add/remove cron jobs by script?What are the differences between ncat, nc and netcat?Cron job not running on libreelecWhy is crond failing to run a non-root crontab on alpine linux?
Infinite Abelian subgroup of infinite non Abelian group example
Anagram holiday
What is the intuition behind short exact sequences of groups; in particular, what is the intuition behind group extensions?
How to model explosives?
How to draw the figure with four pentagons?
90's TV series where a boy goes to another dimension through portal near power lines
Theorems that impeded progress
Can I ask the recruiters in my resume to put the reason why I am rejected?
Has there ever been an airliner design involving reducing generator load by installing solar panels?
CEO ridiculed me with gay jokes and grabbed me and wouldn't let go - now getting pushed out of company
Is "remove commented out code" correct English?
What's the point of deactivating Num Lock on login screens?
Is there a hemisphere-neutral way of specifying a season?
Is it inappropriate for a student to attend their mentor's dissertation defense?
Is it legal for company to use my work email to pretend I still work there?
AES: Why is it a good practice to use only the first 16bytes of a hash for encryption?
What exploit are these user agents trying to use?
Is it possible to create light that imparts a greater proportion of its energy as momentum rather than heat?
In a spin, are both wings stalled?
Do I have a twin with permutated remainders?
How can I prevent hyper evolved versions of regular creatures from wiping out their cousins?
Assassin's bullet with mercury
Why was the shrinking from 8″ made only to 5.25″ and not smaller (4″ or less)?
Emailing HOD to enhance faculty application
Netcat as Daemon
Why does cron silently fail to run sudo stuff in my script?Cron job does not fire up after a timezone changeCalling mailx from crondUsing netcat for port forwardingScreen session started from rc.local is not visible in screen -ls under rootnetcat - unable to put CLIENT IP into $VARHow do I add/remove cron jobs by script?What are the differences between ncat, nc and netcat?Cron job not running on libreelecWhy is crond failing to run a non-root crontab on alpine linux?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I'm trying to set up something that telnets into a device and saves the output to file. I can get it working on the CLI, but not running it at boot (using crontab)
This works running running on the command line:
$ nc <host> <port> | tee -a ~/log.txt
The challenge is getting this to run on system boot using cron. nc doesn't run by itself as a cron, so I run it in screen -d -m and it stays open.
screen -d -m nc <host> <port> | tee -a ~/log.txt
There is no output to the file though. I've also tried:
screen -d -m nc <host> <port> 2>&1 | tee -a ~/log.txt
There is still nothing being output to file... I've seen some people recommending the -d tag on nc, but -d appears to be a delay setting on CentOS 7 and not "ignore STDIN" like others are saying.
centos cron gnu-screen netcat nc
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
add a comment |
I'm trying to set up something that telnets into a device and saves the output to file. I can get it working on the CLI, but not running it at boot (using crontab)
This works running running on the command line:
$ nc <host> <port> | tee -a ~/log.txt
The challenge is getting this to run on system boot using cron. nc doesn't run by itself as a cron, so I run it in screen -d -m and it stays open.
screen -d -m nc <host> <port> | tee -a ~/log.txt
There is no output to the file though. I've also tried:
screen -d -m nc <host> <port> 2>&1 | tee -a ~/log.txt
There is still nothing being output to file... I've seen some people recommending the -d tag on nc, but -d appears to be a delay setting on CentOS 7 and not "ignore STDIN" like others are saying.
centos cron gnu-screen netcat nc
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
see the daemonxinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31
add a comment |
I'm trying to set up something that telnets into a device and saves the output to file. I can get it working on the CLI, but not running it at boot (using crontab)
This works running running on the command line:
$ nc <host> <port> | tee -a ~/log.txt
The challenge is getting this to run on system boot using cron. nc doesn't run by itself as a cron, so I run it in screen -d -m and it stays open.
screen -d -m nc <host> <port> | tee -a ~/log.txt
There is no output to the file though. I've also tried:
screen -d -m nc <host> <port> 2>&1 | tee -a ~/log.txt
There is still nothing being output to file... I've seen some people recommending the -d tag on nc, but -d appears to be a delay setting on CentOS 7 and not "ignore STDIN" like others are saying.
centos cron gnu-screen netcat nc
I'm trying to set up something that telnets into a device and saves the output to file. I can get it working on the CLI, but not running it at boot (using crontab)
This works running running on the command line:
$ nc <host> <port> | tee -a ~/log.txt
The challenge is getting this to run on system boot using cron. nc doesn't run by itself as a cron, so I run it in screen -d -m and it stays open.
screen -d -m nc <host> <port> | tee -a ~/log.txt
There is no output to the file though. I've also tried:
screen -d -m nc <host> <port> 2>&1 | tee -a ~/log.txt
There is still nothing being output to file... I've seen some people recommending the -d tag on nc, but -d appears to be a delay setting on CentOS 7 and not "ignore STDIN" like others are saying.
centos cron gnu-screen netcat nc
centos cron gnu-screen netcat nc
asked Jan 27 '18 at 22:20
Jonathan HurstJonathan Hurst
112
112
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
bumped to the homepage by Community♦ 2 days ago
This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
see the daemonxinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31
add a comment |
see the daemonxinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31
see the daemon
xinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
see the daemon
xinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31
add a comment |
2 Answers
2
active
oldest
votes
Creating a systemd service worked for me. nc would close immediately when I didn't have the --recv-only tag. This seems to keep it running as intended.
[Unit]
Description=test
[Service]
ExecStart=/bin/sh -c 'nc -t --recv-only 10.215.83.80 3004 >> /home/hursjohn/log.txt'
[Install]
WantedBy=multi-user.target
add a comment |
There are some incomprehensible things in your question.
getting this to run on system boot using cron
If you want to run on boot, you either do some magic with systemd (for Redhat and its followers; Centos has succumbed from vs 7 on) or you put it in rc.local for Unix or Unix-like systems. If you put it in cron (or more exactly: crontab) it will run at regular intervals.
I also do not understand why you would want to wrap nc
in a screen
command. Though perhaps possible, it seems like unnecessary overkill.
If you want to run at system boot, there is usually not a stdout availabe, so tee
is also a bad idea. And, if you want to exit your init-script, you'll want nc
to run in the background.
So, I would advice you to put
nohup nc <host> <port> > /home/you/log.txt &
in rc.local
and check with sudo systemctl edit --full rc-local
that rc.local
is run at startup.
Vixie cron has the@reboot
extension - handy for starting things.
– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420116%2fnetcat-as-daemon%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Creating a systemd service worked for me. nc would close immediately when I didn't have the --recv-only tag. This seems to keep it running as intended.
[Unit]
Description=test
[Service]
ExecStart=/bin/sh -c 'nc -t --recv-only 10.215.83.80 3004 >> /home/hursjohn/log.txt'
[Install]
WantedBy=multi-user.target
add a comment |
Creating a systemd service worked for me. nc would close immediately when I didn't have the --recv-only tag. This seems to keep it running as intended.
[Unit]
Description=test
[Service]
ExecStart=/bin/sh -c 'nc -t --recv-only 10.215.83.80 3004 >> /home/hursjohn/log.txt'
[Install]
WantedBy=multi-user.target
add a comment |
Creating a systemd service worked for me. nc would close immediately when I didn't have the --recv-only tag. This seems to keep it running as intended.
[Unit]
Description=test
[Service]
ExecStart=/bin/sh -c 'nc -t --recv-only 10.215.83.80 3004 >> /home/hursjohn/log.txt'
[Install]
WantedBy=multi-user.target
Creating a systemd service worked for me. nc would close immediately when I didn't have the --recv-only tag. This seems to keep it running as intended.
[Unit]
Description=test
[Service]
ExecStart=/bin/sh -c 'nc -t --recv-only 10.215.83.80 3004 >> /home/hursjohn/log.txt'
[Install]
WantedBy=multi-user.target
edited Jan 28 '18 at 18:00
answered Jan 28 '18 at 17:54
Jonathan HurstJonathan Hurst
112
112
add a comment |
add a comment |
There are some incomprehensible things in your question.
getting this to run on system boot using cron
If you want to run on boot, you either do some magic with systemd (for Redhat and its followers; Centos has succumbed from vs 7 on) or you put it in rc.local for Unix or Unix-like systems. If you put it in cron (or more exactly: crontab) it will run at regular intervals.
I also do not understand why you would want to wrap nc
in a screen
command. Though perhaps possible, it seems like unnecessary overkill.
If you want to run at system boot, there is usually not a stdout availabe, so tee
is also a bad idea. And, if you want to exit your init-script, you'll want nc
to run in the background.
So, I would advice you to put
nohup nc <host> <port> > /home/you/log.txt &
in rc.local
and check with sudo systemctl edit --full rc-local
that rc.local
is run at startup.
Vixie cron has the@reboot
extension - handy for starting things.
– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
add a comment |
There are some incomprehensible things in your question.
getting this to run on system boot using cron
If you want to run on boot, you either do some magic with systemd (for Redhat and its followers; Centos has succumbed from vs 7 on) or you put it in rc.local for Unix or Unix-like systems. If you put it in cron (or more exactly: crontab) it will run at regular intervals.
I also do not understand why you would want to wrap nc
in a screen
command. Though perhaps possible, it seems like unnecessary overkill.
If you want to run at system boot, there is usually not a stdout availabe, so tee
is also a bad idea. And, if you want to exit your init-script, you'll want nc
to run in the background.
So, I would advice you to put
nohup nc <host> <port> > /home/you/log.txt &
in rc.local
and check with sudo systemctl edit --full rc-local
that rc.local
is run at startup.
Vixie cron has the@reboot
extension - handy for starting things.
– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
add a comment |
There are some incomprehensible things in your question.
getting this to run on system boot using cron
If you want to run on boot, you either do some magic with systemd (for Redhat and its followers; Centos has succumbed from vs 7 on) or you put it in rc.local for Unix or Unix-like systems. If you put it in cron (or more exactly: crontab) it will run at regular intervals.
I also do not understand why you would want to wrap nc
in a screen
command. Though perhaps possible, it seems like unnecessary overkill.
If you want to run at system boot, there is usually not a stdout availabe, so tee
is also a bad idea. And, if you want to exit your init-script, you'll want nc
to run in the background.
So, I would advice you to put
nohup nc <host> <port> > /home/you/log.txt &
in rc.local
and check with sudo systemctl edit --full rc-local
that rc.local
is run at startup.
There are some incomprehensible things in your question.
getting this to run on system boot using cron
If you want to run on boot, you either do some magic with systemd (for Redhat and its followers; Centos has succumbed from vs 7 on) or you put it in rc.local for Unix or Unix-like systems. If you put it in cron (or more exactly: crontab) it will run at regular intervals.
I also do not understand why you would want to wrap nc
in a screen
command. Though perhaps possible, it seems like unnecessary overkill.
If you want to run at system boot, there is usually not a stdout availabe, so tee
is also a bad idea. And, if you want to exit your init-script, you'll want nc
to run in the background.
So, I would advice you to put
nohup nc <host> <port> > /home/you/log.txt &
in rc.local
and check with sudo systemctl edit --full rc-local
that rc.local
is run at startup.
answered Jan 27 '18 at 23:05
Ljm DullaartLjm Dullaart
749312
749312
Vixie cron has the@reboot
extension - handy for starting things.
– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
add a comment |
Vixie cron has the@reboot
extension - handy for starting things.
– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
Vixie cron has the
@reboot
extension - handy for starting things.– Jasen
Jan 27 '18 at 23:25
Vixie cron has the
@reboot
extension - handy for starting things.– Jasen
Jan 27 '18 at 23:25
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
I do like the idea of running this with systemd. I'll explore that avenue as well. I was unable to get your recomendation to work by adding the line "nohup nc 10.215.83.3 3004 > /home/me/log.txt &" to rc.local. it fails to start. I also tried creading a systemd that runs "/bin/sh -c 'nohup nc 10.215.83.80 3004 > /home/me/log.txt &" and it runs but exits immediately. also all the output is blank to the file it creates.
– Jonathan Hurst
Jan 28 '18 at 1:00
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f420116%2fnetcat-as-daemon%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
see the daemon
xinetd
– Rui F Ribeiro
Jan 27 '18 at 22:36
"nc 10.215.83.80 3004 > log.txt" or "nc 10.215.83.80 3004 | tee -a log.txt" work on the cli, butt running in screen, cron, systemd, etc I'm getting no output to the file. Running this creates the file, but there is no text output.
– Jonathan Hurst
Jan 28 '18 at 4:31