lsf bkill all PEND jobs without killing RUN jobs

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












4















I'v lots bjobs running on lsf, jobs have two status, RUN and PEND. And I want to kill all bjobs with PEND status, how to do that use script? A hard-coded way I think is saving them in a file then parse every line to get the status and key. If the STAT is PEND then pass the key to bkill $key. But this is very complicated, is there any bkill function that can directly do this or a non hard-coded way to kill jobs with a specific status or name?










share|improve this question




























    4















    I'v lots bjobs running on lsf, jobs have two status, RUN and PEND. And I want to kill all bjobs with PEND status, how to do that use script? A hard-coded way I think is saving them in a file then parse every line to get the status and key. If the STAT is PEND then pass the key to bkill $key. But this is very complicated, is there any bkill function that can directly do this or a non hard-coded way to kill jobs with a specific status or name?










    share|improve this question


























      4












      4








      4








      I'v lots bjobs running on lsf, jobs have two status, RUN and PEND. And I want to kill all bjobs with PEND status, how to do that use script? A hard-coded way I think is saving them in a file then parse every line to get the status and key. If the STAT is PEND then pass the key to bkill $key. But this is very complicated, is there any bkill function that can directly do this or a non hard-coded way to kill jobs with a specific status or name?










      share|improve this question
















      I'v lots bjobs running on lsf, jobs have two status, RUN and PEND. And I want to kill all bjobs with PEND status, how to do that use script? A hard-coded way I think is saving them in a file then parse every line to get the status and key. If the STAT is PEND then pass the key to bkill $key. But this is very complicated, is there any bkill function that can directly do this or a non hard-coded way to kill jobs with a specific status or name?







      kill platform-lsf






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Oct 17 '16 at 2:07







      cdnszip

















      asked Oct 12 '16 at 8:03









      cdnszipcdnszip

      7328




      7328




















          2 Answers
          2






          active

          oldest

          votes


















          1














          bjobs can list just the pending jobs with -p. It would be nice if bkill -p would also filter jobs, so bkill -p 0 would kill all the user's pending jobs.



          The best I can think of is some shell magic. While not perfect, it should cover many cases. e.g.,



          bkill `bjobs -p -o jobid | grep -v ^JOBID | tr 'n' ' '`


          bjobs -p -o jobid will list the job ids of the user's pending jobs. grep -v ^JOBID will remove the header. tr will put it in the format that bkill expects. One potential problem is that if the job list is too long then the max command line length or max number of command line arguments will have been exceeded, so bash will complain.



          There's a small race condition here. A job could start between the query and the kill.






          share|improve this answer
































            1














            An alternative solution (also using shell filters as the previous answer, but without the risk of exceeding the no of allowed shell command arguments):



            bjobs -w | grep 'PEND' | awk 'print $1' | xargs bkill



            Basically check for running jobs (-w wide format, no truncating), use grep to filter PENDing job, then select jobIDs with awk, and pass them to bkill via xargs (xargs breaks the no of arguments passed to bkill, avoiding "Argument list too long" kind of errors).






            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',
              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%2f315839%2flsf-bkill-all-pend-jobs-without-killing-run-jobs%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














              bjobs can list just the pending jobs with -p. It would be nice if bkill -p would also filter jobs, so bkill -p 0 would kill all the user's pending jobs.



              The best I can think of is some shell magic. While not perfect, it should cover many cases. e.g.,



              bkill `bjobs -p -o jobid | grep -v ^JOBID | tr 'n' ' '`


              bjobs -p -o jobid will list the job ids of the user's pending jobs. grep -v ^JOBID will remove the header. tr will put it in the format that bkill expects. One potential problem is that if the job list is too long then the max command line length or max number of command line arguments will have been exceeded, so bash will complain.



              There's a small race condition here. A job could start between the query and the kill.






              share|improve this answer





























                1














                bjobs can list just the pending jobs with -p. It would be nice if bkill -p would also filter jobs, so bkill -p 0 would kill all the user's pending jobs.



                The best I can think of is some shell magic. While not perfect, it should cover many cases. e.g.,



                bkill `bjobs -p -o jobid | grep -v ^JOBID | tr 'n' ' '`


                bjobs -p -o jobid will list the job ids of the user's pending jobs. grep -v ^JOBID will remove the header. tr will put it in the format that bkill expects. One potential problem is that if the job list is too long then the max command line length or max number of command line arguments will have been exceeded, so bash will complain.



                There's a small race condition here. A job could start between the query and the kill.






                share|improve this answer



























                  1












                  1








                  1







                  bjobs can list just the pending jobs with -p. It would be nice if bkill -p would also filter jobs, so bkill -p 0 would kill all the user's pending jobs.



                  The best I can think of is some shell magic. While not perfect, it should cover many cases. e.g.,



                  bkill `bjobs -p -o jobid | grep -v ^JOBID | tr 'n' ' '`


                  bjobs -p -o jobid will list the job ids of the user's pending jobs. grep -v ^JOBID will remove the header. tr will put it in the format that bkill expects. One potential problem is that if the job list is too long then the max command line length or max number of command line arguments will have been exceeded, so bash will complain.



                  There's a small race condition here. A job could start between the query and the kill.






                  share|improve this answer















                  bjobs can list just the pending jobs with -p. It would be nice if bkill -p would also filter jobs, so bkill -p 0 would kill all the user's pending jobs.



                  The best I can think of is some shell magic. While not perfect, it should cover many cases. e.g.,



                  bkill `bjobs -p -o jobid | grep -v ^JOBID | tr 'n' ' '`


                  bjobs -p -o jobid will list the job ids of the user's pending jobs. grep -v ^JOBID will remove the header. tr will put it in the format that bkill expects. One potential problem is that if the job list is too long then the max command line length or max number of command line arguments will have been exceeded, so bash will complain.



                  There's a small race condition here. A job could start between the query and the kill.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Oct 25 '16 at 15:18

























                  answered Oct 19 '16 at 17:33









                  Michael ClossonMichael Closson

                  1513




                  1513























                      1














                      An alternative solution (also using shell filters as the previous answer, but without the risk of exceeding the no of allowed shell command arguments):



                      bjobs -w | grep 'PEND' | awk 'print $1' | xargs bkill



                      Basically check for running jobs (-w wide format, no truncating), use grep to filter PENDing job, then select jobIDs with awk, and pass them to bkill via xargs (xargs breaks the no of arguments passed to bkill, avoiding "Argument list too long" kind of errors).






                      share|improve this answer





























                        1














                        An alternative solution (also using shell filters as the previous answer, but without the risk of exceeding the no of allowed shell command arguments):



                        bjobs -w | grep 'PEND' | awk 'print $1' | xargs bkill



                        Basically check for running jobs (-w wide format, no truncating), use grep to filter PENDing job, then select jobIDs with awk, and pass them to bkill via xargs (xargs breaks the no of arguments passed to bkill, avoiding "Argument list too long" kind of errors).






                        share|improve this answer



























                          1












                          1








                          1







                          An alternative solution (also using shell filters as the previous answer, but without the risk of exceeding the no of allowed shell command arguments):



                          bjobs -w | grep 'PEND' | awk 'print $1' | xargs bkill



                          Basically check for running jobs (-w wide format, no truncating), use grep to filter PENDing job, then select jobIDs with awk, and pass them to bkill via xargs (xargs breaks the no of arguments passed to bkill, avoiding "Argument list too long" kind of errors).






                          share|improve this answer















                          An alternative solution (also using shell filters as the previous answer, but without the risk of exceeding the no of allowed shell command arguments):



                          bjobs -w | grep 'PEND' | awk 'print $1' | xargs bkill



                          Basically check for running jobs (-w wide format, no truncating), use grep to filter PENDing job, then select jobIDs with awk, and pass them to bkill via xargs (xargs breaks the no of arguments passed to bkill, avoiding "Argument list too long" kind of errors).







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 22 '17 at 16:53









                          Community

                          1




                          1










                          answered Sep 28 '17 at 10:32









                          SorinSorin

                          111




                          111



























                              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%2f315839%2flsf-bkill-all-pend-jobs-without-killing-run-jobs%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

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

                              Bahrain

                              Postfix configuration issue with fips on centos 7; mailgun relay