delete multiple users












1















I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.



There are two options that are interlinked: the first option is to search users. The code I got is:



last | awk '{print $1,$4,$5,$6,$7} ' 


I have checked this code and it works, it shows me the usernames and the day they last logged on.



For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.



I am using Linux Mint and Vim text editor.










share|improve this question
















bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

    – Anthon
    Dec 5 '14 at 13:41













  • i want to know a way to delete multiple users who haven't logged in for a long period of time

    – user2995836
    Dec 5 '14 at 13:56











  • correction i want to enter a date then delete users who have been inactive since that date

    – user2995836
    Dec 5 '14 at 14:03
















1















I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.



There are two options that are interlinked: the first option is to search users. The code I got is:



last | awk '{print $1,$4,$5,$6,$7} ' 


I have checked this code and it works, it shows me the usernames and the day they last logged on.



For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.



I am using Linux Mint and Vim text editor.










share|improve this question
















bumped to the homepage by Community 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
















  • A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

    – Anthon
    Dec 5 '14 at 13:41













  • i want to know a way to delete multiple users who haven't logged in for a long period of time

    – user2995836
    Dec 5 '14 at 13:56











  • correction i want to enter a date then delete users who have been inactive since that date

    – user2995836
    Dec 5 '14 at 14:03














1












1








1








I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.



There are two options that are interlinked: the first option is to search users. The code I got is:



last | awk '{print $1,$4,$5,$6,$7} ' 


I have checked this code and it works, it shows me the usernames and the day they last logged on.



For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.



I am using Linux Mint and Vim text editor.










share|improve this question
















I am the root user and I am setting up a menu for another user to use. This other user will only get this menu.



There are two options that are interlinked: the first option is to search users. The code I got is:



last | awk '{print $1,$4,$5,$6,$7} ' 


I have checked this code and it works, it shows me the usernames and the day they last logged on.



For the second option: I want to be able to set a date, and them delete users who haven't been active since that date, using the output of the above command.



I am using Linux Mint and Vim text editor.







awk last






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 5 '14 at 13:42









Alaa Ali

9602920




9602920










asked Dec 5 '14 at 12:26









user2995836user2995836

484




484





bumped to the homepage by Community 23 mins 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 23 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.















  • A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

    – Anthon
    Dec 5 '14 at 13:41













  • i want to know a way to delete multiple users who haven't logged in for a long period of time

    – user2995836
    Dec 5 '14 at 13:56











  • correction i want to enter a date then delete users who have been inactive since that date

    – user2995836
    Dec 5 '14 at 14:03



















  • A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

    – Anthon
    Dec 5 '14 at 13:41













  • i want to know a way to delete multiple users who haven't logged in for a long period of time

    – user2995836
    Dec 5 '14 at 13:56











  • correction i want to enter a date then delete users who have been inactive since that date

    – user2995836
    Dec 5 '14 at 14:03

















A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

– Anthon
Dec 5 '14 at 13:41







A question—i.e. a sentence with a question mark (?)—would greatly help to indicate what you try to ask.

– Anthon
Dec 5 '14 at 13:41















i want to know a way to delete multiple users who haven't logged in for a long period of time

– user2995836
Dec 5 '14 at 13:56





i want to know a way to delete multiple users who haven't logged in for a long period of time

– user2995836
Dec 5 '14 at 13:56













correction i want to enter a date then delete users who have been inactive since that date

– user2995836
Dec 5 '14 at 14:03





correction i want to enter a date then delete users who have been inactive since that date

– user2995836
Dec 5 '14 at 14:03










2 Answers
2






active

oldest

votes


















0














You can do it like so:




root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}


Where Num_Days_Since_Last_Login is an integer number of days since last login...






share|improve this answer































    0














    A complete solution :



    #!/bin/bash

    maxdate=$(date -d "$1" +%s) || exit 1
    daysdate=$((($(date +%s)-maxdate)/(3600*24)))

    LANG=C lastlog -b $daysdate -u 1000- |
    awk 'NR>1{print $1}' |
    xargs -n1 echo userdel


    Test it and remove echo to do it forReal™.
    Example usage :



    ./script.sh 'Fri Dec  5 17:00:06 CET 2013'





    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%2f171651%2fdelete-multiple-users%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









      0














      You can do it like so:




      root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}


      Where Num_Days_Since_Last_Login is an integer number of days since last login...






      share|improve this answer




























        0














        You can do it like so:




        root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}


        Where Num_Days_Since_Last_Login is an integer number of days since last login...






        share|improve this answer


























          0












          0








          0







          You can do it like so:




          root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}


          Where Num_Days_Since_Last_Login is an integer number of days since last login...






          share|improve this answer













          You can do it like so:




          root@host# lastlog -b Num_Days_Since_Last_Login | egrep -v "^Username|Never logged in" | awk '{print $1}' | xargs -i userdel {}


          Where Num_Days_Since_Last_Login is an integer number of days since last login...







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Dec 5 '14 at 15:15









          KirillKirill

          323




          323

























              0














              A complete solution :



              #!/bin/bash

              maxdate=$(date -d "$1" +%s) || exit 1
              daysdate=$((($(date +%s)-maxdate)/(3600*24)))

              LANG=C lastlog -b $daysdate -u 1000- |
              awk 'NR>1{print $1}' |
              xargs -n1 echo userdel


              Test it and remove echo to do it forReal™.
              Example usage :



              ./script.sh 'Fri Dec  5 17:00:06 CET 2013'





              share|improve this answer






























                0














                A complete solution :



                #!/bin/bash

                maxdate=$(date -d "$1" +%s) || exit 1
                daysdate=$((($(date +%s)-maxdate)/(3600*24)))

                LANG=C lastlog -b $daysdate -u 1000- |
                awk 'NR>1{print $1}' |
                xargs -n1 echo userdel


                Test it and remove echo to do it forReal™.
                Example usage :



                ./script.sh 'Fri Dec  5 17:00:06 CET 2013'





                share|improve this answer




























                  0












                  0








                  0







                  A complete solution :



                  #!/bin/bash

                  maxdate=$(date -d "$1" +%s) || exit 1
                  daysdate=$((($(date +%s)-maxdate)/(3600*24)))

                  LANG=C lastlog -b $daysdate -u 1000- |
                  awk 'NR>1{print $1}' |
                  xargs -n1 echo userdel


                  Test it and remove echo to do it forReal™.
                  Example usage :



                  ./script.sh 'Fri Dec  5 17:00:06 CET 2013'





                  share|improve this answer















                  A complete solution :



                  #!/bin/bash

                  maxdate=$(date -d "$1" +%s) || exit 1
                  daysdate=$((($(date +%s)-maxdate)/(3600*24)))

                  LANG=C lastlog -b $daysdate -u 1000- |
                  awk 'NR>1{print $1}' |
                  xargs -n1 echo userdel


                  Test it and remove echo to do it forReal™.
                  Example usage :



                  ./script.sh 'Fri Dec  5 17:00:06 CET 2013'






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Dec 5 '14 at 16:40

























                  answered Dec 5 '14 at 16:21









                  Gilles QuenotGilles Quenot

                  16k13951




                  16k13951






























                      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%2f171651%2fdelete-multiple-users%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

                      Histoire des bourses de valeurs

                      Why is there Russian traffic in my log files?

                      Rename multiple files to decrement number in file name?