BASH: calculate number of days to account expiration

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











up vote
2
down vote

favorite












Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.



I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash



join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
where
$1 = username
$9 = number of days since last password change, calculated from 1/1_1970
$14 = number of days to password expiry date, calculated from 1/1_1970


I can get a similar number as $9 and $14 for the current date



expr $(date +%S) /86400


Question:
How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?










share|improve this question



























    up vote
    2
    down vote

    favorite












    Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.



    I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash



    join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
    where
    $1 = username
    $9 = number of days since last password change, calculated from 1/1_1970
    $14 = number of days to password expiry date, calculated from 1/1_1970


    I can get a similar number as $9 and $14 for the current date



    expr $(date +%S) /86400


    Question:
    How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.



      I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash



      join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
      where
      $1 = username
      $9 = number of days since last password change, calculated from 1/1_1970
      $14 = number of days to password expiry date, calculated from 1/1_1970


      I can get a similar number as $9 and $14 for the current date



      expr $(date +%S) /86400


      Question:
      How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?










      share|improve this question















      Objective: Output from Linux username, passwordlastchanged, passwordexpires in human readable format.



      I pulled user info from /etc/passwd and /etc/shadow for users with shell /bin/bash



      join -1 1 -2 1 -t : /etc/passwd /etc/shadow |grep bin/bash|awk -F: 'print $1";"$9";$14'
      where
      $1 = username
      $9 = number of days since last password change, calculated from 1/1_1970
      $14 = number of days to password expiry date, calculated from 1/1_1970


      I can get a similar number as $9 and $14 for the current date



      expr $(date +%S) /86400


      Question:
      How do I output the value of $9-$(date +%s)/86400 and $14-$(date +%s)/86400 in my current one liner?







      bash date accounts






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 42 mins ago









      Rui F Ribeiro

      37.1k1274118




      37.1k1274118










      asked 2 hours ago









      DavDav

      829




      829




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote



          accepted










          Use echo as follows:



           echo "$(($9-$(date +%s)/86400 ))"


          $((...)) is an arithmetic expansion.



          The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.



          $((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.



          or



          echo "$9-$(date +%s)/86400" | bc


          bc stands for basic calculator and it can handle mathematical operations.






          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%2f475777%2fbash-calculate-number-of-days-to-account-expiration%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote



            accepted










            Use echo as follows:



             echo "$(($9-$(date +%s)/86400 ))"


            $((...)) is an arithmetic expansion.



            The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.



            $((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.



            or



            echo "$9-$(date +%s)/86400" | bc


            bc stands for basic calculator and it can handle mathematical operations.






            share|improve this answer


























              up vote
              3
              down vote



              accepted










              Use echo as follows:



               echo "$(($9-$(date +%s)/86400 ))"


              $((...)) is an arithmetic expansion.



              The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.



              $((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.



              or



              echo "$9-$(date +%s)/86400" | bc


              bc stands for basic calculator and it can handle mathematical operations.






              share|improve this answer
























                up vote
                3
                down vote



                accepted







                up vote
                3
                down vote



                accepted






                Use echo as follows:



                 echo "$(($9-$(date +%s)/86400 ))"


                $((...)) is an arithmetic expansion.



                The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.



                $((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.



                or



                echo "$9-$(date +%s)/86400" | bc


                bc stands for basic calculator and it can handle mathematical operations.






                share|improve this answer














                Use echo as follows:



                 echo "$(($9-$(date +%s)/86400 ))"


                $((...)) is an arithmetic expansion.



                The usage of ... in $((...)) will be interpreted as an arithmetic expression. For example, a hexadecimal string will be interpreted as a number and converted to decimal. The whole expression will then be replaced by the numeric value that the expression evaluates to.



                $((...)) should be quoted as to not be affected by the shell's word splitting and filename globbing.



                or



                echo "$9-$(date +%s)/86400" | bc


                bc stands for basic calculator and it can handle mathematical operations.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 1 hour ago

























                answered 1 hour ago









                Goro

                9,63764689




                9,63764689



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f475777%2fbash-calculate-number-of-days-to-account-expiration%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    White Anglo-Saxon Protestant

                    Is the Concept of Multiple Fantasy Races Scientifically Flawed? [closed]

                    One-line joke