Viewing bash history of separate active TTY

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











up vote
4
down vote

favorite












I am working on a script that will help the sysadmins on our team monitor what's going on in other terminals by other logged in users.



One thing I'm stuck on right now is how to view what commands have been typed. I realize that the history doesn't get saved until the user exits or types history -a, but there has to be a way to view what's currently in the history, even if it's stored in memory somewhere.



Is it possibly saved somewhere in /proc/$pid_of_users_bash? I tried to type a command echoing a unique string (EG: echo "foobarbaz", then greping for foobarbaz through any flat files within the associated /proc/PID directory, but no luck.



If anyone has a solution that doesn't involve setting thePROMPT_COMMAND or setting the histappend (like these), that would be greatly appreciated.










share|improve this question























  • If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
    – Christopher
    Oct 2 '17 at 20:16










  • @Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
    – Kusalananda
    Oct 2 '17 at 20:29














up vote
4
down vote

favorite












I am working on a script that will help the sysadmins on our team monitor what's going on in other terminals by other logged in users.



One thing I'm stuck on right now is how to view what commands have been typed. I realize that the history doesn't get saved until the user exits or types history -a, but there has to be a way to view what's currently in the history, even if it's stored in memory somewhere.



Is it possibly saved somewhere in /proc/$pid_of_users_bash? I tried to type a command echoing a unique string (EG: echo "foobarbaz", then greping for foobarbaz through any flat files within the associated /proc/PID directory, but no luck.



If anyone has a solution that doesn't involve setting thePROMPT_COMMAND or setting the histappend (like these), that would be greatly appreciated.










share|improve this question























  • If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
    – Christopher
    Oct 2 '17 at 20:16










  • @Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
    – Kusalananda
    Oct 2 '17 at 20:29












up vote
4
down vote

favorite









up vote
4
down vote

favorite











I am working on a script that will help the sysadmins on our team monitor what's going on in other terminals by other logged in users.



One thing I'm stuck on right now is how to view what commands have been typed. I realize that the history doesn't get saved until the user exits or types history -a, but there has to be a way to view what's currently in the history, even if it's stored in memory somewhere.



Is it possibly saved somewhere in /proc/$pid_of_users_bash? I tried to type a command echoing a unique string (EG: echo "foobarbaz", then greping for foobarbaz through any flat files within the associated /proc/PID directory, but no luck.



If anyone has a solution that doesn't involve setting thePROMPT_COMMAND or setting the histappend (like these), that would be greatly appreciated.










share|improve this question















I am working on a script that will help the sysadmins on our team monitor what's going on in other terminals by other logged in users.



One thing I'm stuck on right now is how to view what commands have been typed. I realize that the history doesn't get saved until the user exits or types history -a, but there has to be a way to view what's currently in the history, even if it's stored in memory somewhere.



Is it possibly saved somewhere in /proc/$pid_of_users_bash? I tried to type a command echoing a unique string (EG: echo "foobarbaz", then greping for foobarbaz through any flat files within the associated /proc/PID directory, but no luck.



If anyone has a solution that doesn't involve setting thePROMPT_COMMAND or setting the histappend (like these), that would be greatly appreciated.







shell tty command-history proc






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Oct 2 '17 at 20:08









Jeff Schaller

32.3k849109




32.3k849109










asked Oct 2 '17 at 19:30









Justin

24018




24018











  • If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
    – Christopher
    Oct 2 '17 at 20:16










  • @Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
    – Kusalananda
    Oct 2 '17 at 20:29
















  • If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
    – Christopher
    Oct 2 '17 at 20:16










  • @Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
    – Kusalananda
    Oct 2 '17 at 20:29















If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
– Christopher
Oct 2 '17 at 20:16




If the question does not attract a solution within the constraints and you do end up punting by using PROMPT_COMMAND... unix.stackexchange.com/questions/207813/…
– Christopher
Oct 2 '17 at 20:16












@Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
– Kusalananda
Oct 2 '17 at 20:29




@Christopher That's what happens on one of the systems I'm using. I'm promptly unsetting PROMPT_COMMAND when logging in there. It also messes with set -x which I have turned on by default...
– Kusalananda
Oct 2 '17 at 20:29










1 Answer
1






active

oldest

votes

















up vote
0
down vote













Bash does not provide information you want. I think you want avoid setting COMMAND_PROMPT and histappend because users may easily overwrites them. But users may completely disable storing commands to history when they set HISTCONTROL="ignorespace" and insert a space before each command. So users that are not willing to be monitored cannot be reliably monitored via bash history.



Ad hoc monitoring a single session can be done over strace. Search for the PID of the user's bash and then call strace -p <bash-pid> 2>&1 |grep "read(0,". The you can see all characters typed by user - including typos and editing commands.



Most of linux distribution provides auditd package. It monitors and audits system components so administrator may get information about system activities in past. A PAM module pam_tty_audit cooperates with auditd and enables or disables TTY activity auditing. I guess you do not need to reinvent wheel and use the pam_tty_audit.






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%2f395707%2fviewing-bash-history-of-separate-active-tty%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
    0
    down vote













    Bash does not provide information you want. I think you want avoid setting COMMAND_PROMPT and histappend because users may easily overwrites them. But users may completely disable storing commands to history when they set HISTCONTROL="ignorespace" and insert a space before each command. So users that are not willing to be monitored cannot be reliably monitored via bash history.



    Ad hoc monitoring a single session can be done over strace. Search for the PID of the user's bash and then call strace -p <bash-pid> 2>&1 |grep "read(0,". The you can see all characters typed by user - including typos and editing commands.



    Most of linux distribution provides auditd package. It monitors and audits system components so administrator may get information about system activities in past. A PAM module pam_tty_audit cooperates with auditd and enables or disables TTY activity auditing. I guess you do not need to reinvent wheel and use the pam_tty_audit.






    share|improve this answer
























      up vote
      0
      down vote













      Bash does not provide information you want. I think you want avoid setting COMMAND_PROMPT and histappend because users may easily overwrites them. But users may completely disable storing commands to history when they set HISTCONTROL="ignorespace" and insert a space before each command. So users that are not willing to be monitored cannot be reliably monitored via bash history.



      Ad hoc monitoring a single session can be done over strace. Search for the PID of the user's bash and then call strace -p <bash-pid> 2>&1 |grep "read(0,". The you can see all characters typed by user - including typos and editing commands.



      Most of linux distribution provides auditd package. It monitors and audits system components so administrator may get information about system activities in past. A PAM module pam_tty_audit cooperates with auditd and enables or disables TTY activity auditing. I guess you do not need to reinvent wheel and use the pam_tty_audit.






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        Bash does not provide information you want. I think you want avoid setting COMMAND_PROMPT and histappend because users may easily overwrites them. But users may completely disable storing commands to history when they set HISTCONTROL="ignorespace" and insert a space before each command. So users that are not willing to be monitored cannot be reliably monitored via bash history.



        Ad hoc monitoring a single session can be done over strace. Search for the PID of the user's bash and then call strace -p <bash-pid> 2>&1 |grep "read(0,". The you can see all characters typed by user - including typos and editing commands.



        Most of linux distribution provides auditd package. It monitors and audits system components so administrator may get information about system activities in past. A PAM module pam_tty_audit cooperates with auditd and enables or disables TTY activity auditing. I guess you do not need to reinvent wheel and use the pam_tty_audit.






        share|improve this answer












        Bash does not provide information you want. I think you want avoid setting COMMAND_PROMPT and histappend because users may easily overwrites them. But users may completely disable storing commands to history when they set HISTCONTROL="ignorespace" and insert a space before each command. So users that are not willing to be monitored cannot be reliably monitored via bash history.



        Ad hoc monitoring a single session can be done over strace. Search for the PID of the user's bash and then call strace -p <bash-pid> 2>&1 |grep "read(0,". The you can see all characters typed by user - including typos and editing commands.



        Most of linux distribution provides auditd package. It monitors and audits system components so administrator may get information about system activities in past. A PAM module pam_tty_audit cooperates with auditd and enables or disables TTY activity auditing. I guess you do not need to reinvent wheel and use the pam_tty_audit.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Oct 15 '17 at 9:22









        Zaboj Campula

        450516




        450516



























             

            draft saved


            draft discarded















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f395707%2fviewing-bash-history-of-separate-active-tty%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