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;








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.










share|improve this question














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 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

















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.










share|improve this question














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 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













0












0








0


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.










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 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

















  • 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
















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










2 Answers
2






active

oldest

votes


















1














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





share|improve this answer
































    0














    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.






    share|improve this answer























    • 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












    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
    );



    );













    draft saved

    draft discarded


















    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









    1














    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





    share|improve this answer





























      1














      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





      share|improve this answer



























        1












        1








        1







        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





        share|improve this answer















        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






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jan 28 '18 at 18:00

























        answered Jan 28 '18 at 17:54









        Jonathan HurstJonathan Hurst

        112




        112























            0














            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.






            share|improve this answer























            • 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
















            0














            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.






            share|improve this answer























            • 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














            0












            0








            0







            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.






            share|improve this answer













            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.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            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


















            • 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


















            draft saved

            draft discarded
















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            getting Checkpoint VPN SSL Network Extender working in the command lineHow to connect to CheckPoint VPN on Ubuntu 18.04LTS?Will the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayVPN SSL Network Extender in FirefoxLinux Checkpoint SNX tool configuration issuesCheck Point - Connect under Linux - snx + OTPSNX VPN Ububuntu 18.XXUsing Checkpoint VPN SSL Network Extender CLI with certificateVPN with network manager (nm-applet) is not workingWill the Linux ( red-hat ) Open VPNC Client connect to checkpoint or nortel VPN gateways?VPN client for linux machine + support checkpoint gatewayImport VPN config files to NetworkManager from command lineTrouble connecting to VPN using network-manager, while command line worksStart a VPN connection with PPTP protocol on command linestarting a docker service daemon breaks the vpn networkCan't connect to vpn with Network-managerVPN SSL Network Extender in FirefoxUsing Checkpoint VPN SSL Network Extender CLI with certificate

            Cannot Extend partition with GParted The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) 2019 Community Moderator Election ResultsCan't increase partition size with GParted?GParted doesn't recognize the unallocated space after my current partitionWhat is the best way to add unallocated space located before to Ubuntu 12.04 partition with GParted live?I can't figure out how to extend my Arch home partition into free spaceGparted Linux Mint 18.1 issueTrying to extend but swap partition is showing as Unknown in Gparted, shows proper from fdiskRearrange partitions in gparted to extend a partitionUnable to extend partition even though unallocated space is next to it using GPartedAllocate free space to root partitiongparted: how to merge unallocated space with a partition

            Marilyn Monroe Ny fiainany manokana | Jereo koa | Meny fitetezanafanitarana azy.