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

  • Home
  • SEARCH
  • 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 7956337
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T03:57:40+00:00 2026-06-04T03:57:40+00:00

when i store the output of history command via ssh in a file i

  • 0

when i store the output of history command via ssh in a file i get something like this

ssh -i private_key user@ip 'export HISTFILE=~/.bash_history; export HISTTIMEFORMAT="%D-%T "; set -o history; history' > myfile.txt

OUTPUT

#1337431451
command

as far as ive learnt this hash string represents a timestamp. how do i change this to a string of my desired format

P.S- using history in ssh is not outputting with timestamps. Tried almost everything. So i guess the next best thing to do would be to convert these # timestamps to a readable date time format myself. How do i go about it?

  • 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-06-04T03:57:41+00:00Added an answer on June 4, 2026 at 3:57 am

    Interesting question: I have tried it but found no simple and clean solution to access the history in a non-interactive shell. However, the format of the history file is simple, and you can write a script to parse it. The following python script might be interesting. Invoke it with ssh -i private_key user@ip 'path/to/script.py .bash_history':

    #! /usr/bin/env python3
    
    import re
    import sys
    import time
    
    if __name__ == '__main__':
        pattern = re.compile(br'^#(\d+)$')
        out = sys.stdout.buffer
        for pathname in sys.argv[1:]:
            with open(pathname, 'rb') as f:
                for line in f:
                    timestamp = 0
                    while line.startswith(b'#'):
                        match = pattern.match(line)
                        if match: timestamp, = map(int, match.groups())
                        line = next(f)
                    out.write(time.strftime('%F %T ', time.localtime(timestamp)).encode('ascii'))
                    out.write(line)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to store shell output into GDB variable in gdbinit? Something like:
I'd like to store the output of the cfdump as a string temporarily. I
Does it possible to execute php file and store its output into some variable?
I have a command that compiles test.cpp and is supposed to store output in
Is it possible to run an external command and store its output in a
How do i create a file which can store the output info? for example,
To store the output of a command as a variable in sh/ksh/bash, you can
I want to store the output of text file into a variable, so I
I can use ggplot2 to store the output of ggplot command to an object
I'm writing a shell script which will store the output of a command in

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.