cron job is not doing anything

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
-1
down vote

favorite












I am trying to run a cron job that runs every 10 minutes to kill the process sshd.



so I did open /etc/crontab as a root and inserted the following line.



*/1 * * * * pkill sshd


I checked with systemctl status sshd after 1,2,3 minutes.
And I see sshd still up & running.



I am using centos7.







share|improve this question


















  • 2




    Isn’t there a * missing?
    – nohillside
    Jan 12 at 20:43










  • Yes I added the start and still the same issue
    – alkabary
    Jan 12 at 20:58










  • what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
    – ivanivan
    Jan 12 at 23:04














up vote
-1
down vote

favorite












I am trying to run a cron job that runs every 10 minutes to kill the process sshd.



so I did open /etc/crontab as a root and inserted the following line.



*/1 * * * * pkill sshd


I checked with systemctl status sshd after 1,2,3 minutes.
And I see sshd still up & running.



I am using centos7.







share|improve this question


















  • 2




    Isn’t there a * missing?
    – nohillside
    Jan 12 at 20:43










  • Yes I added the start and still the same issue
    – alkabary
    Jan 12 at 20:58










  • what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
    – ivanivan
    Jan 12 at 23:04












up vote
-1
down vote

favorite









up vote
-1
down vote

favorite











I am trying to run a cron job that runs every 10 minutes to kill the process sshd.



so I did open /etc/crontab as a root and inserted the following line.



*/1 * * * * pkill sshd


I checked with systemctl status sshd after 1,2,3 minutes.
And I see sshd still up & running.



I am using centos7.







share|improve this question














I am trying to run a cron job that runs every 10 minutes to kill the process sshd.



so I did open /etc/crontab as a root and inserted the following line.



*/1 * * * * pkill sshd


I checked with systemctl status sshd after 1,2,3 minutes.
And I see sshd still up & running.



I am using centos7.









share|improve this question













share|improve this question




share|improve this question








edited Jan 12 at 20:57

























asked Jan 12 at 20:28









alkabary

574823




574823







  • 2




    Isn’t there a * missing?
    – nohillside
    Jan 12 at 20:43










  • Yes I added the start and still the same issue
    – alkabary
    Jan 12 at 20:58










  • what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
    – ivanivan
    Jan 12 at 23:04












  • 2




    Isn’t there a * missing?
    – nohillside
    Jan 12 at 20:43










  • Yes I added the start and still the same issue
    – alkabary
    Jan 12 at 20:58










  • what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
    – ivanivan
    Jan 12 at 23:04







2




2




Isn’t there a * missing?
– nohillside
Jan 12 at 20:43




Isn’t there a * missing?
– nohillside
Jan 12 at 20:43












Yes I added the start and still the same issue
– alkabary
Jan 12 at 20:58




Yes I added the start and still the same issue
– alkabary
Jan 12 at 20:58












what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
– ivanivan
Jan 12 at 23:04




what exactly are you trying to do? disable ssh? better methods. kick off idle ssh connections? better methods. edit your question and tell us your end goal and we can give better help.
– ivanivan
Jan 12 at 23:04










3 Answers
3






active

oldest

votes

















up vote
0
down vote



accepted










There are several problems here (are you sure you wouldn't be better off using auto logoff?):



*/1 * * * * pkill sshd


The "/1" should be "/10" to run every ten minutes.



There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.



It's to be seen whether pkill is in cron's PATH when it runs.



All in all, I'd try with:



*/10 * * * * root /path/to/pkill sshd


Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).






share|improve this answer



























    up vote
    2
    down vote













    you have to edit the file sshd.service and change the line from:



    Restart=on-failure


    to



    Restart=no


    and when you'll kill the process it will not restart.






    share|improve this answer



























      up vote
      2
      down vote













      Why don't you just stop the process all together? etc/init.d/sshd stop
      If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.



      https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html






      share|improve this answer






















        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',
        convertImagesToLinks: false,
        noModals: false,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        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%2f416669%2fcron-job-is-not-doing-anything%23new-answer', 'question_page');

        );

        Post as a guest






























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        0
        down vote



        accepted










        There are several problems here (are you sure you wouldn't be better off using auto logoff?):



        */1 * * * * pkill sshd


        The "/1" should be "/10" to run every ten minutes.



        There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.



        It's to be seen whether pkill is in cron's PATH when it runs.



        All in all, I'd try with:



        */10 * * * * root /path/to/pkill sshd


        Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).






        share|improve this answer
























          up vote
          0
          down vote



          accepted










          There are several problems here (are you sure you wouldn't be better off using auto logoff?):



          */1 * * * * pkill sshd


          The "/1" should be "/10" to run every ten minutes.



          There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.



          It's to be seen whether pkill is in cron's PATH when it runs.



          All in all, I'd try with:



          */10 * * * * root /path/to/pkill sshd


          Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).






          share|improve this answer






















            up vote
            0
            down vote



            accepted







            up vote
            0
            down vote



            accepted






            There are several problems here (are you sure you wouldn't be better off using auto logoff?):



            */1 * * * * pkill sshd


            The "/1" should be "/10" to run every ten minutes.



            There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.



            It's to be seen whether pkill is in cron's PATH when it runs.



            All in all, I'd try with:



            */10 * * * * root /path/to/pkill sshd


            Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).






            share|improve this answer












            There are several problems here (are you sure you wouldn't be better off using auto logoff?):



            */1 * * * * pkill sshd


            The "/1" should be "/10" to run every ten minutes.



            There is no user specification: I suspect that you'll find some message to the tune of "unknown user pkill" in the syslog.



            It's to be seen whether pkill is in cron's PATH when it runs.



            All in all, I'd try with:



            */10 * * * * root /path/to/pkill sshd


            Then you have the problem of sshd restarting after having been killed, as D'Arcy Nader pointed out in his answer (but that's probably all right, otherwise you wouldn't want to do serial killing through cron).







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jan 12 at 21:17









            LSerni

            2,326615




            2,326615






















                up vote
                2
                down vote













                you have to edit the file sshd.service and change the line from:



                Restart=on-failure


                to



                Restart=no


                and when you'll kill the process it will not restart.






                share|improve this answer
























                  up vote
                  2
                  down vote













                  you have to edit the file sshd.service and change the line from:



                  Restart=on-failure


                  to



                  Restart=no


                  and when you'll kill the process it will not restart.






                  share|improve this answer






















                    up vote
                    2
                    down vote










                    up vote
                    2
                    down vote









                    you have to edit the file sshd.service and change the line from:



                    Restart=on-failure


                    to



                    Restart=no


                    and when you'll kill the process it will not restart.






                    share|improve this answer












                    you have to edit the file sshd.service and change the line from:



                    Restart=on-failure


                    to



                    Restart=no


                    and when you'll kill the process it will not restart.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 12 at 20:43









                    D'Arcy Nader

                    678414




                    678414




















                        up vote
                        2
                        down vote













                        Why don't you just stop the process all together? etc/init.d/sshd stop
                        If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.



                        https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html






                        share|improve this answer


























                          up vote
                          2
                          down vote













                          Why don't you just stop the process all together? etc/init.d/sshd stop
                          If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.



                          https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html






                          share|improve this answer
























                            up vote
                            2
                            down vote










                            up vote
                            2
                            down vote









                            Why don't you just stop the process all together? etc/init.d/sshd stop
                            If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.



                            https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html






                            share|improve this answer














                            Why don't you just stop the process all together? etc/init.d/sshd stop
                            If you you are worried it will start up on the next reboot, you could add this command to crontab via crontab -e add */1 * * * * etc/init.d/sshd stop . This is untested at the moment.



                            https://www.centos.org/docs/5/html/Deployment_Guide-en-US/ch-autotasks.html







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Jan 14 at 11:50









                            Jeff Schaller

                            31.8k848109




                            31.8k848109










                            answered Jan 12 at 22:18









                            Govna

                            7817




                            7817






















                                 

                                draft saved


                                draft discarded


























                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function ()
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f416669%2fcron-job-is-not-doing-anything%23new-answer', 'question_page');

                                );

                                Post as a guest













































































                                Popular posts from this blog

                                How to check contact read email or not when send email to Individual?

                                Bahrain

                                Postfix configuration issue with fips on centos 7; mailgun relay