Add current date/time to ps output











up vote
1
down vote

favorite












I want to log my cpu and memory usage. There are loads of posts out there giving different options using ps, top, python, etc. I really like the ps way of doing it. In my case, I call:



ps -o user -o pid  -o pmem -o pcpu -u dxd9163


Which gives a nice table:



enter image description here



Because I'm logging this data (every ten minutes), I would like to add the date/time information to each row of the table as with:



date +%Y/%m/%d/%H:%M


I don't want the process time, how long it was running or when it was started, I just want the time the snapshot was taken. So in the figure above, a new field, time would be there with all the same info for each snapshot.



It seems the ps function has a deprecated option that may have worked before but doesn't anymore (utime).



Any idea how to do this? It's probably easy but I'm new to Linux.



My final goal is to log every 10 minutes for as long at it takes into a usage.txt file ram and cpu usage for my user.










share|improve this question






















  • Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
    – pbhj
    Dec 6 at 15:16















up vote
1
down vote

favorite












I want to log my cpu and memory usage. There are loads of posts out there giving different options using ps, top, python, etc. I really like the ps way of doing it. In my case, I call:



ps -o user -o pid  -o pmem -o pcpu -u dxd9163


Which gives a nice table:



enter image description here



Because I'm logging this data (every ten minutes), I would like to add the date/time information to each row of the table as with:



date +%Y/%m/%d/%H:%M


I don't want the process time, how long it was running or when it was started, I just want the time the snapshot was taken. So in the figure above, a new field, time would be there with all the same info for each snapshot.



It seems the ps function has a deprecated option that may have worked before but doesn't anymore (utime).



Any idea how to do this? It's probably easy but I'm new to Linux.



My final goal is to log every 10 minutes for as long at it takes into a usage.txt file ram and cpu usage for my user.










share|improve this question






















  • Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
    – pbhj
    Dec 6 at 15:16













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to log my cpu and memory usage. There are loads of posts out there giving different options using ps, top, python, etc. I really like the ps way of doing it. In my case, I call:



ps -o user -o pid  -o pmem -o pcpu -u dxd9163


Which gives a nice table:



enter image description here



Because I'm logging this data (every ten minutes), I would like to add the date/time information to each row of the table as with:



date +%Y/%m/%d/%H:%M


I don't want the process time, how long it was running or when it was started, I just want the time the snapshot was taken. So in the figure above, a new field, time would be there with all the same info for each snapshot.



It seems the ps function has a deprecated option that may have worked before but doesn't anymore (utime).



Any idea how to do this? It's probably easy but I'm new to Linux.



My final goal is to log every 10 minutes for as long at it takes into a usage.txt file ram and cpu usage for my user.










share|improve this question













I want to log my cpu and memory usage. There are loads of posts out there giving different options using ps, top, python, etc. I really like the ps way of doing it. In my case, I call:



ps -o user -o pid  -o pmem -o pcpu -u dxd9163


Which gives a nice table:



enter image description here



Because I'm logging this data (every ten minutes), I would like to add the date/time information to each row of the table as with:



date +%Y/%m/%d/%H:%M


I don't want the process time, how long it was running or when it was started, I just want the time the snapshot was taken. So in the figure above, a new field, time would be there with all the same info for each snapshot.



It seems the ps function has a deprecated option that may have worked before but doesn't anymore (utime).



Any idea how to do this? It's probably easy but I'm new to Linux.



My final goal is to log every 10 minutes for as long at it takes into a usage.txt file ram and cpu usage for my user.







log ps






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 6 at 14:28









Bastien

1105




1105












  • Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
    – pbhj
    Dec 6 at 15:16


















  • Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
    – pbhj
    Dec 6 at 15:16
















Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
– pbhj
Dec 6 at 15:16




Did you look at atop, it seems closer to the info you'll get by repeatedly calling ps.
– pbhj
Dec 6 at 15:16










1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










One trick is to replace each "start of line"
with "start of line, timestamp ":



ps -o user -o pid  -o pmem -o pcpu -u dxd9163 | sed "s#^#$(date +%Y/%m/%d/%H:%M) #"


Usually sed's substitute operator uses a slash as separator (s/…/…/) but since
the timestamp already contains slashes, this won't work. I thus used a different
separator (s#…#…#).






share|improve this answer





















    Your Answer








    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "89"
    };
    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: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    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%2faskubuntu.com%2fquestions%2f1098939%2fadd-current-date-time-to-ps-output%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote



    accepted










    One trick is to replace each "start of line"
    with "start of line, timestamp ":



    ps -o user -o pid  -o pmem -o pcpu -u dxd9163 | sed "s#^#$(date +%Y/%m/%d/%H:%M) #"


    Usually sed's substitute operator uses a slash as separator (s/…/…/) but since
    the timestamp already contains slashes, this won't work. I thus used a different
    separator (s#…#…#).






    share|improve this answer

























      up vote
      2
      down vote



      accepted










      One trick is to replace each "start of line"
      with "start of line, timestamp ":



      ps -o user -o pid  -o pmem -o pcpu -u dxd9163 | sed "s#^#$(date +%Y/%m/%d/%H:%M) #"


      Usually sed's substitute operator uses a slash as separator (s/…/…/) but since
      the timestamp already contains slashes, this won't work. I thus used a different
      separator (s#…#…#).






      share|improve this answer























        up vote
        2
        down vote



        accepted







        up vote
        2
        down vote



        accepted






        One trick is to replace each "start of line"
        with "start of line, timestamp ":



        ps -o user -o pid  -o pmem -o pcpu -u dxd9163 | sed "s#^#$(date +%Y/%m/%d/%H:%M) #"


        Usually sed's substitute operator uses a slash as separator (s/…/…/) but since
        the timestamp already contains slashes, this won't work. I thus used a different
        separator (s#…#…#).






        share|improve this answer












        One trick is to replace each "start of line"
        with "start of line, timestamp ":



        ps -o user -o pid  -o pmem -o pcpu -u dxd9163 | sed "s#^#$(date +%Y/%m/%d/%H:%M) #"


        Usually sed's substitute operator uses a slash as separator (s/…/…/) but since
        the timestamp already contains slashes, this won't work. I thus used a different
        separator (s#…#…#).







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Dec 6 at 14:38









        PerlDuck

        5,14911231




        5,14911231






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Ask Ubuntu!


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





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • 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%2faskubuntu.com%2fquestions%2f1098939%2fadd-current-date-time-to-ps-output%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

            flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

            Mangá

             ⁒  ․,‪⁊‑⁙ ⁖, ⁇‒※‌, †,⁖‗‌⁝    ‾‸⁘,‖⁔⁣,⁂‾
”‑,‥–,‬ ,⁀‹⁋‴⁑ ‒ ,‴⁋”‼ ⁨,‷⁔„ ‰′,‐‚ ‥‡‎“‷⁃⁨⁅⁣,⁔
⁇‘⁔⁡⁏⁌⁡‿‶‏⁨ ⁣⁕⁖⁨⁩⁥‽⁀  ‴‬⁜‟ ⁃‣‧⁕‮ …‍⁨‴ ⁩,⁚⁖‫ ,‵ ⁀,‮⁝‣‣ ⁑  ⁂– ․, ‾‽ ‏⁁“⁗‸ ‾… ‹‡⁌⁎‸‘ ‡⁏⁌‪ ‵⁛ ‎⁨ ―⁦⁤⁄⁕