Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6355237
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T22:43:31+00:00 2026-05-24T22:43:31+00:00

I was wondering, out of curiosity, if it is possible to code a bash

  • 0

I was wondering, out of curiosity, if it is possible to code a bash script logs all the command run in a Bash/SSH session. I know history is suppose to log all the commands run but it seems to be very unreliable!

I have been messing about this morning and came up with the following bash script which does log what the user runs in the terminal but does not run all the commands correctly.

prompt_read() {
  echo -n “$(whoami)@$(hostname):$(pwd)~$ “
  read userinput
}

prompt_read

while :; do
  if [[ $userinput != exit ]]; then
    logger "logit $userinput"
    bash -c "$userinput"
    prompt_read
  else
    kill -1 $PPID
  fi
done

Is anyone aware of anything that logs commands better and more reliably than history

Cheers

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T22:43:31+00:00Added an answer on May 24, 2026 at 10:43 pm

    The reason why history seems unreliable to you is because it only writes to history at the end of a BASH session, so you could lose commands.

    I have a few things in my bash profile:

    HISTFILESIZE=10000 # how many lines of history to store in the history file
    
    HISTSIZE=10000 # how many lines of history to store in a session ( I think )
    
    HISTCONTROL=ignoredups # ignore duplicate commands
    
    shopt -s histappend # append history, rather than having sessions obliterate existing history
    PROMPT_COMMAND="history -a;$PROMPT_COMMAND"
    

    The last few are the important ones, setting your PROMPT_COMMAND with history -a will make history append immediately, rather than post-session. And setting shopt -s histappend will make bash sessions append to the history file, rather than overwrite existing histories.

    Some more info: http://linuxcommando.blogspot.com/2007/11/keeping-command-history-across-multiple.html

    Additionally, if this is useful to you, you can change the name of the history file you use for a particular bash session with the HISTFILE environment variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just out of curiosity I was wondering how is it possible for the javascript
I was just wondering out of curiosity if it was possible to display large
Out of pure curiosity, I am wondering if it's possible (no doubt it is)
I am wondering if there is any technique out there for making HTML code
I'm wondering why this code section prints out the following: print request.user.has_perm('bug_tracking.is_developer'): + str(request.user.has_perm('bug_tracking.is_developer'))
I know this question could be in vain, but it's just out of curiosity,
Just out of curiosity, I'm wondering how gmail does what it does. After looking
Out of curiosity I'm wondering if I can do something about this because I'm
Just out of curiosity I wanted to know if is there a way to
Out of curiosity, I'm wondering about the best (easiest, fastest, shortest, etc; make your

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.